Няма описание

CVMakerPageView.swift 64KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622
  1. //
  2. // CVMakerPageView.swift
  3. // App for Indeed
  4. //
  5. // Template gallery for the CV Maker sidebar destination. Light-theme rendering
  6. // inspired by a dark reference UI: page header, category toggle, style chips,
  7. // 4-column thumbnail grid with hover Preview overlay, and a sticky bottom CTA.
  8. //
  9. import Cocoa
  10. // MARK: - Data model
  11. enum CVCategoryGroup: Hashable {
  12. case designBased
  13. case professionBased
  14. var title: String {
  15. switch self {
  16. case .designBased: return "Design-Based"
  17. case .professionBased: return "Profession-Based"
  18. }
  19. }
  20. }
  21. enum CVDesignFamily: String, CaseIterable, Hashable {
  22. case professional, modern, creative, minimal, executive
  23. var title: String {
  24. switch self {
  25. case .professional: return "Professional"
  26. case .modern: return "Modern"
  27. case .creative: return "Creative"
  28. case .minimal: return "Minimal"
  29. case .executive: return "Executive"
  30. }
  31. }
  32. }
  33. /// Visual recipe used by the mini preview renderer so every template can vary
  34. /// the headline style, accent line, and sidebar layout without bespoke views.
  35. struct CVTemplate: Hashable {
  36. enum Headline: Hashable {
  37. /// Big name centered above the body.
  38. case centered
  39. /// Name aligned to the leading edge, role beneath it.
  40. case leftAligned
  41. /// Name on the leading edge with circular initials avatar on the trailing edge.
  42. case leftWithInitials
  43. /// Initials avatar above a centered name (single column).
  44. case avatarStacked
  45. }
  46. enum Accent: Hashable {
  47. case none
  48. case redUnderline
  49. case redBar
  50. case blueBar
  51. }
  52. enum SidebarSide: Hashable { case leading, trailing }
  53. enum Layout: Hashable {
  54. case singleColumn
  55. case twoColumn(sidebar: SidebarSide, tinted: Bool)
  56. }
  57. enum SectionLabelStyle: Hashable {
  58. case uppercase
  59. case slashed // "// EXPERIENCE"
  60. case bracketed // "[ EXPERIENCE ]"
  61. }
  62. let id: String
  63. let name: String
  64. let family: CVDesignFamily
  65. let headline: Headline
  66. let accent: Accent
  67. let layout: Layout
  68. let sectionLabelStyle: SectionLabelStyle
  69. }
  70. // MARK: - Catalog
  71. enum CVTemplateCatalog {
  72. static let all: [CVTemplate] = [
  73. // Minimal family (matches the reference screenshot)
  74. CVTemplate(
  75. id: "paper-white",
  76. name: "Paper White",
  77. family: .minimal,
  78. headline: .centered,
  79. accent: .none,
  80. layout: .singleColumn,
  81. sectionLabelStyle: .uppercase
  82. ),
  83. CVTemplate(
  84. id: "swiss",
  85. name: "Swiss",
  86. family: .minimal,
  87. headline: .centered,
  88. accent: .redUnderline,
  89. layout: .twoColumn(sidebar: .leading, tinted: false),
  90. sectionLabelStyle: .uppercase
  91. ),
  92. CVTemplate(
  93. id: "mono",
  94. name: "Mono",
  95. family: .minimal,
  96. headline: .leftAligned,
  97. accent: .redUnderline,
  98. layout: .singleColumn,
  99. sectionLabelStyle: .slashed
  100. ),
  101. CVTemplate(
  102. id: "airy",
  103. name: "Airy",
  104. family: .minimal,
  105. headline: .leftWithInitials,
  106. accent: .none,
  107. layout: .twoColumn(sidebar: .trailing, tinted: false),
  108. sectionLabelStyle: .uppercase
  109. ),
  110. CVTemplate(
  111. id: "tabular",
  112. name: "Tabular",
  113. family: .minimal,
  114. headline: .leftAligned,
  115. accent: .none,
  116. layout: .singleColumn,
  117. sectionLabelStyle: .bracketed
  118. ),
  119. CVTemplate(
  120. id: "facet",
  121. name: "Facet",
  122. family: .minimal,
  123. headline: .avatarStacked,
  124. accent: .none,
  125. layout: .twoColumn(sidebar: .leading, tinted: true),
  126. sectionLabelStyle: .uppercase
  127. ),
  128. // Professional family
  129. CVTemplate(
  130. id: "corporate",
  131. name: "Corporate",
  132. family: .professional,
  133. headline: .leftAligned,
  134. accent: .blueBar,
  135. layout: .singleColumn,
  136. sectionLabelStyle: .uppercase
  137. ),
  138. CVTemplate(
  139. id: "atlas",
  140. name: "Atlas",
  141. family: .professional,
  142. headline: .centered,
  143. accent: .blueBar,
  144. layout: .twoColumn(sidebar: .leading, tinted: true),
  145. sectionLabelStyle: .uppercase
  146. ),
  147. CVTemplate(
  148. id: "ledger",
  149. name: "Ledger",
  150. family: .professional,
  151. headline: .leftAligned,
  152. accent: .blueBar,
  153. layout: .twoColumn(sidebar: .trailing, tinted: false),
  154. sectionLabelStyle: .uppercase
  155. ),
  156. CVTemplate(
  157. id: "harbor",
  158. name: "Harbor",
  159. family: .professional,
  160. headline: .leftWithInitials,
  161. accent: .none,
  162. layout: .twoColumn(sidebar: .leading, tinted: true),
  163. sectionLabelStyle: .uppercase
  164. ),
  165. CVTemplate(
  166. id: "metro",
  167. name: "Metro",
  168. family: .professional,
  169. headline: .centered,
  170. accent: .blueBar,
  171. layout: .singleColumn,
  172. sectionLabelStyle: .uppercase
  173. ),
  174. CVTemplate(
  175. id: "pinstripe",
  176. name: "Pinstripe",
  177. family: .professional,
  178. headline: .leftAligned,
  179. accent: .blueBar,
  180. layout: .twoColumn(sidebar: .leading, tinted: false),
  181. sectionLabelStyle: .uppercase
  182. ),
  183. // Modern family
  184. CVTemplate(
  185. id: "vertex",
  186. name: "Vertex",
  187. family: .modern,
  188. headline: .leftWithInitials,
  189. accent: .blueBar,
  190. layout: .twoColumn(sidebar: .leading, tinted: true),
  191. sectionLabelStyle: .slashed
  192. ),
  193. CVTemplate(
  194. id: "linea",
  195. name: "Linea",
  196. family: .modern,
  197. headline: .leftAligned,
  198. accent: .blueBar,
  199. layout: .singleColumn,
  200. sectionLabelStyle: .slashed
  201. ),
  202. CVTemplate(
  203. id: "prism",
  204. name: "Prism",
  205. family: .modern,
  206. headline: .avatarStacked,
  207. accent: .blueBar,
  208. layout: .twoColumn(sidebar: .trailing, tinted: true),
  209. sectionLabelStyle: .uppercase
  210. ),
  211. CVTemplate(
  212. id: "circuit",
  213. name: "Circuit",
  214. family: .modern,
  215. headline: .leftAligned,
  216. accent: .blueBar,
  217. layout: .twoColumn(sidebar: .trailing, tinted: false),
  218. sectionLabelStyle: .slashed
  219. ),
  220. CVTemplate(
  221. id: "north",
  222. name: "North",
  223. family: .modern,
  224. headline: .leftWithInitials,
  225. accent: .none,
  226. layout: .twoColumn(sidebar: .leading, tinted: false),
  227. sectionLabelStyle: .uppercase
  228. ),
  229. CVTemplate(
  230. id: "axis",
  231. name: "Axis",
  232. family: .modern,
  233. headline: .centered,
  234. accent: .blueBar,
  235. layout: .singleColumn,
  236. sectionLabelStyle: .bracketed
  237. ),
  238. // Creative family
  239. CVTemplate(
  240. id: "marigold",
  241. name: "Marigold",
  242. family: .creative,
  243. headline: .avatarStacked,
  244. accent: .redBar,
  245. layout: .twoColumn(sidebar: .leading, tinted: true),
  246. sectionLabelStyle: .slashed
  247. ),
  248. CVTemplate(
  249. id: "ember",
  250. name: "Ember",
  251. family: .creative,
  252. headline: .leftWithInitials,
  253. accent: .redBar,
  254. layout: .twoColumn(sidebar: .trailing, tinted: true),
  255. sectionLabelStyle: .slashed
  256. ),
  257. CVTemplate(
  258. id: "lattice",
  259. name: "Lattice",
  260. family: .creative,
  261. headline: .leftAligned,
  262. accent: .redUnderline,
  263. layout: .singleColumn,
  264. sectionLabelStyle: .bracketed
  265. ),
  266. CVTemplate(
  267. id: "bloom",
  268. name: "Bloom",
  269. family: .creative,
  270. headline: .avatarStacked,
  271. accent: .redBar,
  272. layout: .singleColumn,
  273. sectionLabelStyle: .slashed
  274. ),
  275. CVTemplate(
  276. id: "studio",
  277. name: "Studio",
  278. family: .creative,
  279. headline: .leftWithInitials,
  280. accent: .redUnderline,
  281. layout: .twoColumn(sidebar: .leading, tinted: true),
  282. sectionLabelStyle: .uppercase
  283. ),
  284. CVTemplate(
  285. id: "kite",
  286. name: "Kite",
  287. family: .creative,
  288. headline: .centered,
  289. accent: .redBar,
  290. layout: .twoColumn(sidebar: .trailing, tinted: false),
  291. sectionLabelStyle: .slashed
  292. ),
  293. // Executive family
  294. CVTemplate(
  295. id: "regent",
  296. name: "Regent",
  297. family: .executive,
  298. headline: .centered,
  299. accent: .blueBar,
  300. layout: .twoColumn(sidebar: .leading, tinted: true),
  301. sectionLabelStyle: .uppercase
  302. ),
  303. CVTemplate(
  304. id: "monarch",
  305. name: "Monarch",
  306. family: .executive,
  307. headline: .centered,
  308. accent: .blueBar,
  309. layout: .singleColumn,
  310. sectionLabelStyle: .uppercase
  311. ),
  312. CVTemplate(
  313. id: "sterling",
  314. name: "Sterling",
  315. family: .executive,
  316. headline: .leftAligned,
  317. accent: .blueBar,
  318. layout: .twoColumn(sidebar: .trailing, tinted: false),
  319. sectionLabelStyle: .uppercase
  320. ),
  321. CVTemplate(
  322. id: "summit",
  323. name: "Summit",
  324. family: .executive,
  325. headline: .centered,
  326. accent: .redUnderline,
  327. layout: .twoColumn(sidebar: .leading, tinted: false),
  328. sectionLabelStyle: .uppercase
  329. ),
  330. CVTemplate(
  331. id: "estate",
  332. name: "Estate",
  333. family: .executive,
  334. headline: .leftWithInitials,
  335. accent: .blueBar,
  336. layout: .twoColumn(sidebar: .trailing, tinted: true),
  337. sectionLabelStyle: .uppercase
  338. ),
  339. CVTemplate(
  340. id: "chairman",
  341. name: "Chairman",
  342. family: .executive,
  343. headline: .leftAligned,
  344. accent: .blueBar,
  345. layout: .singleColumn,
  346. sectionLabelStyle: .uppercase
  347. )
  348. ]
  349. }
  350. // MARK: - View
  351. /// Standalone NSView for the CV Maker route. Renders the template gallery with
  352. /// header, segmented category groups, family chips, a thumbnail grid, and a
  353. /// bottom CTA. Hosts inside the same `nonHomeHost` slot as Saved Jobs/Settings.
  354. final class CVMakerPageView: NSView {
  355. /// Light-theme palette aligned with the rest of the dashboard (brand blue + neutral grays on white).
  356. private enum Palette {
  357. static let pageBackground = NSColor(srgbRed: 1, green: 1, blue: 1, alpha: 1)
  358. static let mutedSurface = NSColor(srgbRed: 247 / 255, green: 247 / 255, blue: 247 / 255, alpha: 1)
  359. static let chipRestFill = NSColor(srgbRed: 244 / 255, green: 246 / 255, blue: 250 / 255, alpha: 1)
  360. static let chipBorder = NSColor(srgbRed: 222 / 255, green: 226 / 255, blue: 233 / 255, alpha: 1)
  361. static let chipHoverFill = NSColor(srgbRed: 236 / 255, green: 240 / 255, blue: 246 / 255, alpha: 1)
  362. static let chipBadgeBackground = NSColor(srgbRed: 233 / 255, green: 236 / 255, blue: 241 / 255, alpha: 1)
  363. static let chipBadgeText = NSColor(srgbRed: 90 / 255, green: 102 / 255, blue: 121 / 255, alpha: 1)
  364. static let activeChipBackground = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1)
  365. static let activeChipHover = NSColor(srgbRed: 28 / 255, green: 70 / 255, blue: 140 / 255, alpha: 1)
  366. static let activeChipText = NSColor.white
  367. static let activeChipBadgeBackground = NSColor.white.withAlphaComponent(0.22)
  368. static let activeChipBadgeText = NSColor.white
  369. static let primaryText = NSColor(srgbRed: 31 / 255, green: 41 / 255, blue: 55 / 255, alpha: 1)
  370. static let secondaryText = NSColor(srgbRed: 100 / 255, green: 116 / 255, blue: 139 / 255, alpha: 1)
  371. static let cardBorder = NSColor(srgbRed: 216 / 255, green: 223 / 255, blue: 233 / 255, alpha: 1)
  372. static let cardBorderHover = NSColor(srgbRed: 178 / 255, green: 196 / 255, blue: 225 / 255, alpha: 1)
  373. static let cardBorderSelected = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1)
  374. static let cardFooter = NSColor(srgbRed: 250 / 255, green: 251 / 255, blue: 253 / 255, alpha: 1)
  375. static let previewSurface = NSColor(srgbRed: 252 / 255, green: 252 / 255, blue: 252 / 255, alpha: 1)
  376. static let previewPaper = NSColor.white
  377. static let previewSidebarTint = NSColor(srgbRed: 244 / 255, green: 246 / 255, blue: 250 / 255, alpha: 1)
  378. static let previewInk = NSColor(srgbRed: 38 / 255, green: 50 / 255, blue: 71 / 255, alpha: 1)
  379. static let previewMuted = NSColor(srgbRed: 165 / 255, green: 175 / 255, blue: 192 / 255, alpha: 1)
  380. static let previewAccentRed = NSColor(srgbRed: 207 / 255, green: 67 / 255, blue: 50 / 255, alpha: 1)
  381. static let previewAccentBlue = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1)
  382. static let ctaBackground = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1)
  383. static let ctaHover = NSColor(srgbRed: 28 / 255, green: 70 / 255, blue: 140 / 255, alpha: 1)
  384. static let ctaText = NSColor.white
  385. static let overlayTint = NSColor.black.withAlphaComponent(0.45)
  386. }
  387. private static let columns: Int = 4
  388. private let titleLabel = NSTextField(labelWithString: "Templates")
  389. private let subtitleLabel = NSTextField(labelWithString: "Browse and select a template for your CV")
  390. private let groupTabsRow = NSStackView()
  391. private let familyChipsRow = NSStackView()
  392. private let scrollView = NSScrollView()
  393. private let gridDocument = TopFlippedView()
  394. private let gridStack = NSStackView()
  395. private let ctaButton = CVHoverableButton(title: "Use Template & Select Profile →", target: nil, action: nil)
  396. private var selectedGroup: CVCategoryGroup = .designBased
  397. private var selectedFamily: CVDesignFamily? = nil // nil == "All"
  398. private var selectedTemplateID: String? = "paper-white"
  399. /// Shown immediately; replaced when `CVTemplateFetchService` returns AI-generated entries.
  400. private var activeCatalog: [CVTemplate] = CVTemplateCatalog.all
  401. private var groupTabButtons: [CVCategoryGroup: CVChipButton] = [:]
  402. private var familyChipButtons: [CVDesignFamily?: CVChipButton] = [:]
  403. private var templateCardsByID: [String: CVTemplateCard] = [:]
  404. override init(frame frameRect: NSRect) {
  405. super.init(frame: frameRect)
  406. configureLayout()
  407. reloadFamilyChips()
  408. reloadTemplateGrid()
  409. updateSelectedChipStates()
  410. beginLoadingAICatalogIfPossible()
  411. }
  412. @available(*, unavailable)
  413. required init?(coder: NSCoder) {
  414. fatalError("init(coder:) has not been implemented")
  415. }
  416. override func layout() {
  417. super.layout()
  418. // Re-measure the grid in case the container width changed (window resize).
  419. layoutGridCardsIfNeeded()
  420. }
  421. // MARK: Setup
  422. private func configureLayout() {
  423. wantsLayer = true
  424. layer?.backgroundColor = Palette.pageBackground.cgColor
  425. titleLabel.font = .systemFont(ofSize: 22, weight: .bold)
  426. titleLabel.textColor = Palette.primaryText
  427. titleLabel.alignment = .left
  428. subtitleLabel.font = .systemFont(ofSize: 13, weight: .regular)
  429. subtitleLabel.textColor = Palette.secondaryText
  430. subtitleLabel.alignment = .left
  431. subtitleLabel.maximumNumberOfLines = 1
  432. let headerStack = NSStackView(views: [titleLabel, subtitleLabel])
  433. headerStack.orientation = .vertical
  434. headerStack.spacing = 4
  435. headerStack.alignment = .leading
  436. headerStack.translatesAutoresizingMaskIntoConstraints = false
  437. groupTabsRow.orientation = .horizontal
  438. groupTabsRow.spacing = 8
  439. groupTabsRow.alignment = .centerY
  440. groupTabsRow.translatesAutoresizingMaskIntoConstraints = false
  441. configureGroupTabs()
  442. familyChipsRow.orientation = .horizontal
  443. familyChipsRow.spacing = 8
  444. familyChipsRow.alignment = .centerY
  445. familyChipsRow.translatesAutoresizingMaskIntoConstraints = false
  446. gridStack.orientation = .vertical
  447. gridStack.spacing = 16
  448. gridStack.alignment = .leading
  449. gridStack.distribution = .fill
  450. gridStack.translatesAutoresizingMaskIntoConstraints = false
  451. gridDocument.translatesAutoresizingMaskIntoConstraints = false
  452. gridDocument.addSubview(gridStack)
  453. NSLayoutConstraint.activate([
  454. gridStack.leadingAnchor.constraint(equalTo: gridDocument.leadingAnchor),
  455. gridStack.trailingAnchor.constraint(equalTo: gridDocument.trailingAnchor),
  456. gridStack.topAnchor.constraint(equalTo: gridDocument.topAnchor),
  457. gridStack.bottomAnchor.constraint(equalTo: gridDocument.bottomAnchor)
  458. ])
  459. scrollView.translatesAutoresizingMaskIntoConstraints = false
  460. scrollView.hasVerticalScroller = true
  461. scrollView.hasHorizontalScroller = false
  462. scrollView.scrollerStyle = .legacy
  463. scrollView.autohidesScrollers = true
  464. scrollView.drawsBackground = false
  465. scrollView.borderType = .noBorder
  466. scrollView.documentView = gridDocument
  467. NSLayoutConstraint.activate([
  468. gridDocument.topAnchor.constraint(equalTo: scrollView.contentView.topAnchor),
  469. gridDocument.leadingAnchor.constraint(equalTo: scrollView.contentView.leadingAnchor),
  470. gridDocument.widthAnchor.constraint(equalTo: scrollView.contentView.widthAnchor)
  471. ])
  472. ctaButton.translatesAutoresizingMaskIntoConstraints = false
  473. styleCTAButton(ctaButton)
  474. ctaButton.target = self
  475. ctaButton.action = #selector(didTapUseTemplate)
  476. addSubview(headerStack)
  477. addSubview(groupTabsRow)
  478. addSubview(familyChipsRow)
  479. addSubview(scrollView)
  480. addSubview(ctaButton)
  481. let horizontalInset: CGFloat = 32
  482. NSLayoutConstraint.activate([
  483. headerStack.leadingAnchor.constraint(equalTo: leadingAnchor, constant: horizontalInset),
  484. headerStack.trailingAnchor.constraint(lessThanOrEqualTo: trailingAnchor, constant: -horizontalInset),
  485. headerStack.topAnchor.constraint(equalTo: topAnchor, constant: 8),
  486. groupTabsRow.leadingAnchor.constraint(equalTo: leadingAnchor, constant: horizontalInset),
  487. groupTabsRow.trailingAnchor.constraint(lessThanOrEqualTo: trailingAnchor, constant: -horizontalInset),
  488. groupTabsRow.topAnchor.constraint(equalTo: headerStack.bottomAnchor, constant: 18),
  489. familyChipsRow.leadingAnchor.constraint(equalTo: leadingAnchor, constant: horizontalInset),
  490. familyChipsRow.trailingAnchor.constraint(lessThanOrEqualTo: trailingAnchor, constant: -horizontalInset),
  491. familyChipsRow.topAnchor.constraint(equalTo: groupTabsRow.bottomAnchor, constant: 14),
  492. scrollView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: horizontalInset),
  493. scrollView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -horizontalInset),
  494. scrollView.topAnchor.constraint(equalTo: familyChipsRow.bottomAnchor, constant: 16),
  495. scrollView.bottomAnchor.constraint(equalTo: ctaButton.topAnchor, constant: -16),
  496. ctaButton.leadingAnchor.constraint(equalTo: leadingAnchor, constant: horizontalInset),
  497. ctaButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -horizontalInset),
  498. ctaButton.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -24),
  499. ctaButton.heightAnchor.constraint(equalToConstant: 50)
  500. ])
  501. }
  502. private func configureGroupTabs() {
  503. groupTabsRow.arrangedSubviews.forEach {
  504. groupTabsRow.removeArrangedSubview($0)
  505. $0.removeFromSuperview()
  506. }
  507. groupTabButtons.removeAll()
  508. let groups: [(CVCategoryGroup, String)] = [
  509. (.designBased, "rectangle.3.group"),
  510. (.professionBased, "person.2")
  511. ]
  512. for (group, symbolName) in groups {
  513. let count = templates(forGroup: group, family: nil).count
  514. let chip = CVChipButton(
  515. title: group.title,
  516. badgeText: "\(count)",
  517. leadingSymbol: symbolName,
  518. style: .pillLarge
  519. )
  520. chip.translatesAutoresizingMaskIntoConstraints = false
  521. chip.onSelect = { [weak self] in self?.didSelectGroup(group) }
  522. groupTabsRow.addArrangedSubview(chip)
  523. groupTabButtons[group] = chip
  524. }
  525. }
  526. private func reloadFamilyChips() {
  527. familyChipsRow.arrangedSubviews.forEach {
  528. familyChipsRow.removeArrangedSubview($0)
  529. $0.removeFromSuperview()
  530. }
  531. familyChipButtons.removeAll()
  532. let allCount = templates(forGroup: selectedGroup, family: nil).count
  533. let allChip = CVChipButton(title: "All", badgeText: "\(allCount)", leadingSymbol: nil, style: .pillSmall)
  534. allChip.onSelect = { [weak self] in self?.didSelectFamily(nil) }
  535. familyChipsRow.addArrangedSubview(allChip)
  536. familyChipButtons[nil] = allChip
  537. for family in CVDesignFamily.allCases {
  538. let count = templates(forGroup: selectedGroup, family: family).count
  539. let chip = CVChipButton(title: family.title, badgeText: "\(count)", leadingSymbol: nil, style: .pillSmall)
  540. chip.onSelect = { [weak self] in self?.didSelectFamily(family) }
  541. familyChipsRow.addArrangedSubview(chip)
  542. familyChipButtons[family] = chip
  543. }
  544. }
  545. // MARK: Data filtering
  546. private func templates(forGroup group: CVCategoryGroup, family: CVDesignFamily?) -> [CVTemplate] {
  547. // The catalog is design-driven; profession-based reuses the same templates
  548. // so the gallery is fully populated for both groups in this preview build.
  549. let base = activeCatalog
  550. guard let family else { return base }
  551. _ = group
  552. return base.filter { $0.family == family }
  553. }
  554. private var visibleTemplates: [CVTemplate] {
  555. templates(forGroup: selectedGroup, family: selectedFamily)
  556. }
  557. // MARK: Grid
  558. private func reloadTemplateGrid() {
  559. gridStack.arrangedSubviews.forEach {
  560. gridStack.removeArrangedSubview($0)
  561. $0.removeFromSuperview()
  562. }
  563. templateCardsByID.removeAll()
  564. let templates = visibleTemplates
  565. if templates.isEmpty {
  566. let empty = NSTextField(labelWithString: "No templates yet for this category.")
  567. empty.font = .systemFont(ofSize: 13)
  568. empty.textColor = Palette.secondaryText
  569. gridStack.addArrangedSubview(empty)
  570. return
  571. }
  572. let columns = Self.columns
  573. var index = 0
  574. while index < templates.count {
  575. let row = NSStackView()
  576. row.orientation = .horizontal
  577. row.spacing = 16
  578. row.distribution = .fillEqually
  579. row.alignment = .top
  580. row.translatesAutoresizingMaskIntoConstraints = false
  581. row.setHuggingPriority(.defaultLow, for: .horizontal)
  582. for column in 0..<columns {
  583. let position = index + column
  584. if position < templates.count {
  585. let template = templates[position]
  586. let card = CVTemplateCard(template: template, palette: palette())
  587. card.translatesAutoresizingMaskIntoConstraints = false
  588. card.onSelect = { [weak self] in self?.didSelectTemplate(template.id) }
  589. card.onPreview = { [weak self] in self?.didPreviewTemplate(template.id) }
  590. row.addArrangedSubview(card)
  591. templateCardsByID[template.id] = card
  592. } else {
  593. let filler = NSView()
  594. filler.translatesAutoresizingMaskIntoConstraints = false
  595. row.addArrangedSubview(filler)
  596. }
  597. }
  598. gridStack.addArrangedSubview(row)
  599. row.widthAnchor.constraint(equalTo: gridStack.widthAnchor).isActive = true
  600. index += columns
  601. }
  602. if selectedTemplateID == nil || templateCardsByID[selectedTemplateID ?? ""] == nil {
  603. selectedTemplateID = templates.first?.id
  604. }
  605. applySelectionToCards()
  606. }
  607. private func layoutGridCardsIfNeeded() {
  608. // Stack will resize the rows; nothing else to do — kept as a hook for future enhancements.
  609. }
  610. private func applySelectionToCards() {
  611. for (id, card) in templateCardsByID {
  612. card.isSelected = (id == selectedTemplateID)
  613. }
  614. }
  615. private func palette() -> CVTemplateCard.Palette {
  616. CVTemplateCard.Palette(
  617. border: Palette.cardBorder,
  618. borderHover: Palette.cardBorderHover,
  619. borderSelected: Palette.cardBorderSelected,
  620. footerBackground: Palette.cardFooter,
  621. previewSurface: Palette.previewSurface,
  622. previewPaper: Palette.previewPaper,
  623. previewSidebarTint: Palette.previewSidebarTint,
  624. previewInk: Palette.previewInk,
  625. previewMuted: Palette.previewMuted,
  626. previewAccentRed: Palette.previewAccentRed,
  627. previewAccentBlue: Palette.previewAccentBlue,
  628. primaryText: Palette.primaryText,
  629. secondaryText: Palette.secondaryText,
  630. overlayTint: Palette.overlayTint
  631. )
  632. }
  633. // MARK: Selection
  634. private func didSelectGroup(_ group: CVCategoryGroup) {
  635. guard selectedGroup != group else { return }
  636. selectedGroup = group
  637. selectedFamily = nil
  638. reloadFamilyChips()
  639. reloadTemplateGrid()
  640. updateSelectedChipStates()
  641. }
  642. private func didSelectFamily(_ family: CVDesignFamily?) {
  643. guard selectedFamily != family else { return }
  644. selectedFamily = family
  645. reloadTemplateGrid()
  646. updateSelectedChipStates()
  647. }
  648. private func didSelectTemplate(_ id: String) {
  649. selectedTemplateID = id
  650. applySelectionToCards()
  651. }
  652. private func didPreviewTemplate(_ id: String) {
  653. selectedTemplateID = id
  654. applySelectionToCards()
  655. guard let template = activeCatalog.first(where: { $0.id == id }) else { return }
  656. presentPlaceholderAlert(
  657. title: "Preview \"\(template.name)\"",
  658. message: "Full-page previews and PDF export are coming soon."
  659. )
  660. }
  661. @objc private func didTapUseTemplate() {
  662. guard let id = selectedTemplateID,
  663. let template = activeCatalog.first(where: { $0.id == id }) else {
  664. presentPlaceholderAlert(title: "Pick a template", message: "Select a template first, then choose a profile to continue.")
  665. return
  666. }
  667. presentPlaceholderAlert(
  668. title: "Use \"\(template.name)\"",
  669. message: "Profile selection and CV editing are not available in this preview build yet."
  670. )
  671. }
  672. private func updateSelectedChipStates() {
  673. for (group, chip) in groupTabButtons {
  674. chip.isSelected = (group == selectedGroup)
  675. }
  676. for (family, chip) in familyChipButtons {
  677. chip.isSelected = (family == selectedFamily)
  678. }
  679. }
  680. private func styleCTAButton(_ button: CVHoverableButton) {
  681. button.title = "Use Template & Select Profile →"
  682. button.font = .systemFont(ofSize: 14, weight: .semibold)
  683. button.isBordered = false
  684. button.bezelStyle = .rounded
  685. button.focusRingType = .none
  686. button.contentTintColor = Palette.ctaText
  687. button.wantsLayer = true
  688. button.layer?.cornerRadius = 12
  689. button.layer?.backgroundColor = Palette.ctaBackground.cgColor
  690. button.pointerCursor = true
  691. let attrs: [NSAttributedString.Key: Any] = [
  692. .foregroundColor: Palette.ctaText,
  693. .font: NSFont.systemFont(ofSize: 14, weight: .semibold)
  694. ]
  695. button.attributedTitle = NSAttributedString(string: button.title, attributes: attrs)
  696. button.hoverHandler = { [weak button] hovering in
  697. button?.layer?.backgroundColor = (hovering ? Palette.ctaHover : Palette.ctaBackground).cgColor
  698. }
  699. }
  700. private func beginLoadingAICatalogIfPossible() {
  701. guard OpenAIConfiguration.hasAPIKey else { return }
  702. let defaultSubtitle = subtitleLabel.stringValue
  703. subtitleLabel.stringValue = "Fetching AI-curated templates…"
  704. CVTemplateFetchService.shared.fetchTemplates { [weak self] result in
  705. DispatchQueue.main.async {
  706. guard let self else { return }
  707. switch result {
  708. case .success(let list):
  709. self.subtitleLabel.stringValue = defaultSubtitle
  710. if !list.isEmpty {
  711. self.activeCatalog = list
  712. self.configureGroupTabs()
  713. self.reloadFamilyChips()
  714. self.reloadTemplateGrid()
  715. self.updateSelectedChipStates()
  716. }
  717. case .failure:
  718. self.subtitleLabel.stringValue = "Couldn’t load AI templates — showing the built-in gallery."
  719. DispatchQueue.main.asyncAfter(deadline: .now() + 5.5) { [weak self] in
  720. self?.subtitleLabel.stringValue = defaultSubtitle
  721. }
  722. }
  723. }
  724. }
  725. }
  726. private func presentPlaceholderAlert(title: String, message: String) {
  727. let alert = NSAlert()
  728. alert.messageText = title
  729. alert.informativeText = message
  730. alert.alertStyle = .informational
  731. alert.addButton(withTitle: "OK")
  732. if let window {
  733. alert.beginSheetModal(for: window)
  734. } else {
  735. alert.runModal()
  736. }
  737. }
  738. }
  739. // MARK: - Chip / pill button
  740. /// Reusable pill button used for both the top section toggle ("Design-Based"
  741. /// vs "Profession-Based") and the family filter chips. Switches between an
  742. /// active brand-blue state and a soft neutral state, with an inline count badge.
  743. private final class CVChipButton: NSView {
  744. enum Style { case pillLarge, pillSmall }
  745. var onSelect: (() -> Void)?
  746. var isSelected: Bool = false { didSet { applyState() } }
  747. private let style: Style
  748. private let titleLabel = NSTextField(labelWithString: "")
  749. private let badgeLabel = NSTextField(labelWithString: "")
  750. private let badgePill = NSView()
  751. private let symbolView = NSImageView()
  752. private let stack = NSStackView()
  753. private var isHovering: Bool = false
  754. private var didPushCursor: Bool = false
  755. private var trackingArea: NSTrackingArea?
  756. private enum Palette {
  757. static let restFill = NSColor(srgbRed: 247 / 255, green: 249 / 255, blue: 252 / 255, alpha: 1)
  758. static let restBorder = NSColor(srgbRed: 222 / 255, green: 226 / 255, blue: 233 / 255, alpha: 1)
  759. static let hoverFill = NSColor(srgbRed: 238 / 255, green: 241 / 255, blue: 247 / 255, alpha: 1)
  760. static let activeFill = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1)
  761. static let activeFillHover = NSColor(srgbRed: 28 / 255, green: 70 / 255, blue: 140 / 255, alpha: 1)
  762. static let restText = NSColor(srgbRed: 71 / 255, green: 85 / 255, blue: 105 / 255, alpha: 1)
  763. static let activeText = NSColor.white
  764. static let restBadge = NSColor(srgbRed: 230 / 255, green: 234 / 255, blue: 240 / 255, alpha: 1)
  765. static let restBadgeText = NSColor(srgbRed: 100 / 255, green: 116 / 255, blue: 139 / 255, alpha: 1)
  766. static let activeBadge = NSColor.white.withAlphaComponent(0.22)
  767. static let activeBadgeText = NSColor.white
  768. }
  769. init(title: String, badgeText: String, leadingSymbol: String?, style: Style) {
  770. self.style = style
  771. super.init(frame: .zero)
  772. wantsLayer = true
  773. translatesAutoresizingMaskIntoConstraints = false
  774. let height: CGFloat = style == .pillLarge ? 38 : 30
  775. layer?.cornerRadius = height / 2
  776. layer?.borderWidth = 1
  777. heightAnchor.constraint(equalToConstant: height).isActive = true
  778. titleLabel.stringValue = title
  779. titleLabel.font = .systemFont(ofSize: style == .pillLarge ? 13 : 12, weight: .semibold)
  780. titleLabel.isBordered = false
  781. titleLabel.drawsBackground = false
  782. titleLabel.isEditable = false
  783. titleLabel.isSelectable = false
  784. badgeLabel.stringValue = badgeText
  785. badgeLabel.font = .systemFont(ofSize: 10.5, weight: .semibold)
  786. badgeLabel.alignment = .center
  787. badgeLabel.isBordered = false
  788. badgeLabel.drawsBackground = false
  789. badgeLabel.isEditable = false
  790. badgeLabel.isSelectable = false
  791. badgePill.translatesAutoresizingMaskIntoConstraints = false
  792. badgePill.wantsLayer = true
  793. badgePill.layer?.cornerRadius = 9
  794. badgePill.addSubview(badgeLabel)
  795. badgeLabel.translatesAutoresizingMaskIntoConstraints = false
  796. NSLayoutConstraint.activate([
  797. badgeLabel.leadingAnchor.constraint(equalTo: badgePill.leadingAnchor, constant: 7),
  798. badgeLabel.trailingAnchor.constraint(equalTo: badgePill.trailingAnchor, constant: -7),
  799. badgeLabel.centerYAnchor.constraint(equalTo: badgePill.centerYAnchor),
  800. badgePill.heightAnchor.constraint(equalToConstant: 18),
  801. badgePill.widthAnchor.constraint(greaterThanOrEqualToConstant: 22)
  802. ])
  803. stack.orientation = .horizontal
  804. stack.spacing = 8
  805. stack.alignment = .centerY
  806. stack.translatesAutoresizingMaskIntoConstraints = false
  807. if let symbol = leadingSymbol, style == .pillLarge {
  808. symbolView.translatesAutoresizingMaskIntoConstraints = false
  809. symbolView.image = NSImage(systemSymbolName: symbol, accessibilityDescription: nil)
  810. symbolView.symbolConfiguration = NSImage.SymbolConfiguration(pointSize: 13, weight: .semibold)
  811. stack.addArrangedSubview(symbolView)
  812. }
  813. stack.addArrangedSubview(titleLabel)
  814. stack.addArrangedSubview(badgePill)
  815. addSubview(stack)
  816. let horizontalInset: CGFloat = style == .pillLarge ? 16 : 12
  817. NSLayoutConstraint.activate([
  818. stack.leadingAnchor.constraint(equalTo: leadingAnchor, constant: horizontalInset),
  819. stack.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -horizontalInset),
  820. stack.centerYAnchor.constraint(equalTo: centerYAnchor)
  821. ])
  822. setContentHuggingPriority(.required, for: .horizontal)
  823. applyState()
  824. }
  825. @available(*, unavailable)
  826. required init?(coder: NSCoder) {
  827. fatalError("init(coder:) has not been implemented")
  828. }
  829. override func hitTest(_ point: NSPoint) -> NSView? {
  830. guard let superview else { return super.hitTest(point) }
  831. let local = convert(point, from: superview)
  832. return bounds.contains(local) ? self : nil
  833. }
  834. override func mouseDown(with event: NSEvent) {
  835. onSelect?()
  836. }
  837. override func updateTrackingAreas() {
  838. super.updateTrackingAreas()
  839. if let area = trackingArea { removeTrackingArea(area) }
  840. let area = NSTrackingArea(
  841. rect: bounds,
  842. options: [.activeInKeyWindow, .mouseEnteredAndExited, .inVisibleRect],
  843. owner: self,
  844. userInfo: nil
  845. )
  846. addTrackingArea(area)
  847. trackingArea = area
  848. }
  849. override func mouseEntered(with event: NSEvent) {
  850. super.mouseEntered(with: event)
  851. isHovering = true
  852. applyState()
  853. if !didPushCursor {
  854. NSCursor.pointingHand.push()
  855. didPushCursor = true
  856. }
  857. }
  858. override func mouseExited(with event: NSEvent) {
  859. super.mouseExited(with: event)
  860. isHovering = false
  861. applyState()
  862. if didPushCursor {
  863. NSCursor.pop()
  864. didPushCursor = false
  865. }
  866. }
  867. override func viewWillMove(toWindow newWindow: NSWindow?) {
  868. super.viewWillMove(toWindow: newWindow)
  869. if newWindow == nil, didPushCursor {
  870. NSCursor.pop()
  871. didPushCursor = false
  872. isHovering = false
  873. }
  874. }
  875. private func applyState() {
  876. let fill: NSColor
  877. let border: NSColor
  878. let textColor: NSColor
  879. let badgeFill: NSColor
  880. let badgeText: NSColor
  881. if isSelected {
  882. fill = isHovering ? Palette.activeFillHover : Palette.activeFill
  883. border = fill
  884. textColor = Palette.activeText
  885. badgeFill = Palette.activeBadge
  886. badgeText = Palette.activeBadgeText
  887. } else {
  888. fill = isHovering ? Palette.hoverFill : Palette.restFill
  889. border = Palette.restBorder
  890. textColor = Palette.restText
  891. badgeFill = Palette.restBadge
  892. badgeText = Palette.restBadgeText
  893. }
  894. layer?.backgroundColor = fill.cgColor
  895. layer?.borderColor = border.cgColor
  896. titleLabel.textColor = textColor
  897. symbolView.contentTintColor = textColor
  898. badgePill.layer?.backgroundColor = badgeFill.cgColor
  899. badgeLabel.textColor = badgeText
  900. }
  901. }
  902. // MARK: - Template card
  903. /// Bordered card holding the mini CV preview, a hover "Preview" overlay, and a
  904. /// footer with the template name + family. Maintains its own hover/selected
  905. /// states so the parent can stay declarative.
  906. private final class CVTemplateCard: NSView {
  907. struct Palette {
  908. let border: NSColor
  909. let borderHover: NSColor
  910. let borderSelected: NSColor
  911. let footerBackground: NSColor
  912. let previewSurface: NSColor
  913. let previewPaper: NSColor
  914. let previewSidebarTint: NSColor
  915. let previewInk: NSColor
  916. let previewMuted: NSColor
  917. let previewAccentRed: NSColor
  918. let previewAccentBlue: NSColor
  919. let primaryText: NSColor
  920. let secondaryText: NSColor
  921. let overlayTint: NSColor
  922. }
  923. var onSelect: (() -> Void)?
  924. var onPreview: (() -> Void)?
  925. var isSelected: Bool = false { didSet { applyBorder() } }
  926. private let template: CVTemplate
  927. private let palette: Palette
  928. private let previewSurface = NSView()
  929. private let preview: CVTemplatePreviewView
  930. private let nameLabel = NSTextField(labelWithString: "")
  931. private let categoryLabel = NSTextField(labelWithString: "")
  932. private let overlay = NSView()
  933. private let overlayBadge = NSView()
  934. private let overlayBadgeLabel = NSTextField(labelWithString: "Preview")
  935. private let overlayBadgeIcon = NSImageView()
  936. private var trackingArea: NSTrackingArea?
  937. private var isHovering: Bool = false
  938. private var didPushCursor: Bool = false
  939. init(template: CVTemplate, palette: Palette) {
  940. self.template = template
  941. self.palette = palette
  942. self.preview = CVTemplatePreviewView(template: template, palette: palette)
  943. super.init(frame: .zero)
  944. wantsLayer = true
  945. layer?.cornerRadius = 14
  946. layer?.borderWidth = 1
  947. layer?.masksToBounds = true
  948. translatesAutoresizingMaskIntoConstraints = false
  949. heightAnchor.constraint(greaterThanOrEqualToConstant: 280).isActive = true
  950. previewSurface.translatesAutoresizingMaskIntoConstraints = false
  951. previewSurface.wantsLayer = true
  952. previewSurface.layer?.backgroundColor = palette.previewSurface.cgColor
  953. preview.translatesAutoresizingMaskIntoConstraints = false
  954. previewSurface.addSubview(preview)
  955. nameLabel.stringValue = template.name
  956. nameLabel.font = .systemFont(ofSize: 13, weight: .semibold)
  957. nameLabel.textColor = palette.primaryText
  958. nameLabel.isBordered = false
  959. nameLabel.drawsBackground = false
  960. nameLabel.isEditable = false
  961. nameLabel.isSelectable = false
  962. categoryLabel.stringValue = template.family.title
  963. categoryLabel.font = .systemFont(ofSize: 11.5, weight: .regular)
  964. categoryLabel.textColor = palette.secondaryText
  965. categoryLabel.isBordered = false
  966. categoryLabel.drawsBackground = false
  967. categoryLabel.isEditable = false
  968. categoryLabel.isSelectable = false
  969. let footerStack = NSStackView(views: [nameLabel, categoryLabel])
  970. footerStack.orientation = .vertical
  971. footerStack.spacing = 2
  972. footerStack.alignment = .leading
  973. footerStack.translatesAutoresizingMaskIntoConstraints = false
  974. let footer = NSView()
  975. footer.translatesAutoresizingMaskIntoConstraints = false
  976. footer.wantsLayer = true
  977. footer.layer?.backgroundColor = palette.footerBackground.cgColor
  978. footer.addSubview(footerStack)
  979. NSLayoutConstraint.activate([
  980. footerStack.leadingAnchor.constraint(equalTo: footer.leadingAnchor, constant: 14),
  981. footerStack.trailingAnchor.constraint(lessThanOrEqualTo: footer.trailingAnchor, constant: -14),
  982. footerStack.topAnchor.constraint(equalTo: footer.topAnchor, constant: 12),
  983. footerStack.bottomAnchor.constraint(equalTo: footer.bottomAnchor, constant: -12)
  984. ])
  985. addSubview(previewSurface)
  986. addSubview(footer)
  987. addSubview(overlay)
  988. configureOverlay()
  989. NSLayoutConstraint.activate([
  990. previewSurface.topAnchor.constraint(equalTo: topAnchor),
  991. previewSurface.leadingAnchor.constraint(equalTo: leadingAnchor),
  992. previewSurface.trailingAnchor.constraint(equalTo: trailingAnchor),
  993. previewSurface.heightAnchor.constraint(greaterThanOrEqualToConstant: 230),
  994. preview.topAnchor.constraint(equalTo: previewSurface.topAnchor, constant: 16),
  995. preview.leadingAnchor.constraint(equalTo: previewSurface.leadingAnchor, constant: 18),
  996. preview.trailingAnchor.constraint(equalTo: previewSurface.trailingAnchor, constant: -18),
  997. preview.bottomAnchor.constraint(equalTo: previewSurface.bottomAnchor, constant: -16),
  998. footer.topAnchor.constraint(equalTo: previewSurface.bottomAnchor),
  999. footer.leadingAnchor.constraint(equalTo: leadingAnchor),
  1000. footer.trailingAnchor.constraint(equalTo: trailingAnchor),
  1001. footer.bottomAnchor.constraint(equalTo: bottomAnchor),
  1002. overlay.topAnchor.constraint(equalTo: previewSurface.topAnchor),
  1003. overlay.leadingAnchor.constraint(equalTo: previewSurface.leadingAnchor),
  1004. overlay.trailingAnchor.constraint(equalTo: previewSurface.trailingAnchor),
  1005. overlay.bottomAnchor.constraint(equalTo: previewSurface.bottomAnchor)
  1006. ])
  1007. applyBorder()
  1008. }
  1009. @available(*, unavailable)
  1010. required init?(coder: NSCoder) {
  1011. fatalError("init(coder:) has not been implemented")
  1012. }
  1013. private func configureOverlay() {
  1014. overlay.translatesAutoresizingMaskIntoConstraints = false
  1015. overlay.wantsLayer = true
  1016. overlay.layer?.backgroundColor = palette.overlayTint.cgColor
  1017. overlay.alphaValue = 0
  1018. overlay.isHidden = false
  1019. overlayBadge.translatesAutoresizingMaskIntoConstraints = false
  1020. overlayBadge.wantsLayer = true
  1021. overlayBadge.layer?.backgroundColor = NSColor.black.withAlphaComponent(0.78).cgColor
  1022. overlayBadge.layer?.cornerRadius = 16
  1023. overlayBadgeIcon.translatesAutoresizingMaskIntoConstraints = false
  1024. overlayBadgeIcon.image = NSImage(systemSymbolName: "eye", accessibilityDescription: nil)
  1025. overlayBadgeIcon.symbolConfiguration = NSImage.SymbolConfiguration(pointSize: 11, weight: .semibold)
  1026. overlayBadgeIcon.contentTintColor = .white
  1027. overlayBadgeLabel.font = .systemFont(ofSize: 12, weight: .semibold)
  1028. overlayBadgeLabel.textColor = .white
  1029. overlayBadgeLabel.isBordered = false
  1030. overlayBadgeLabel.drawsBackground = false
  1031. overlayBadgeLabel.isEditable = false
  1032. overlayBadgeLabel.isSelectable = false
  1033. let badgeStack = NSStackView(views: [overlayBadgeIcon, overlayBadgeLabel])
  1034. badgeStack.orientation = .horizontal
  1035. badgeStack.spacing = 6
  1036. badgeStack.alignment = .centerY
  1037. badgeStack.translatesAutoresizingMaskIntoConstraints = false
  1038. overlayBadge.addSubview(badgeStack)
  1039. overlay.addSubview(overlayBadge)
  1040. NSLayoutConstraint.activate([
  1041. badgeStack.leadingAnchor.constraint(equalTo: overlayBadge.leadingAnchor, constant: 14),
  1042. badgeStack.trailingAnchor.constraint(equalTo: overlayBadge.trailingAnchor, constant: -14),
  1043. badgeStack.topAnchor.constraint(equalTo: overlayBadge.topAnchor, constant: 8),
  1044. badgeStack.bottomAnchor.constraint(equalTo: overlayBadge.bottomAnchor, constant: -8),
  1045. overlayBadge.centerXAnchor.constraint(equalTo: overlay.centerXAnchor),
  1046. overlayBadge.centerYAnchor.constraint(equalTo: overlay.centerYAnchor)
  1047. ])
  1048. }
  1049. override func hitTest(_ point: NSPoint) -> NSView? {
  1050. guard let superview else { return super.hitTest(point) }
  1051. let local = convert(point, from: superview)
  1052. return bounds.contains(local) ? self : nil
  1053. }
  1054. override func mouseDown(with event: NSEvent) {
  1055. let local = convert(event.locationInWindow, from: nil)
  1056. if overlay.frame.contains(local) {
  1057. onPreview?()
  1058. } else {
  1059. onSelect?()
  1060. }
  1061. }
  1062. override func updateTrackingAreas() {
  1063. super.updateTrackingAreas()
  1064. if let area = trackingArea { removeTrackingArea(area) }
  1065. let area = NSTrackingArea(
  1066. rect: bounds,
  1067. options: [.activeInKeyWindow, .mouseEnteredAndExited, .inVisibleRect],
  1068. owner: self,
  1069. userInfo: nil
  1070. )
  1071. addTrackingArea(area)
  1072. trackingArea = area
  1073. }
  1074. override func mouseEntered(with event: NSEvent) {
  1075. super.mouseEntered(with: event)
  1076. isHovering = true
  1077. animateOverlay(visible: true)
  1078. applyBorder()
  1079. if !didPushCursor {
  1080. NSCursor.pointingHand.push()
  1081. didPushCursor = true
  1082. }
  1083. }
  1084. override func mouseExited(with event: NSEvent) {
  1085. super.mouseExited(with: event)
  1086. isHovering = false
  1087. animateOverlay(visible: false)
  1088. applyBorder()
  1089. if didPushCursor {
  1090. NSCursor.pop()
  1091. didPushCursor = false
  1092. }
  1093. }
  1094. override func viewWillMove(toWindow newWindow: NSWindow?) {
  1095. super.viewWillMove(toWindow: newWindow)
  1096. if newWindow == nil, didPushCursor {
  1097. NSCursor.pop()
  1098. didPushCursor = false
  1099. isHovering = false
  1100. }
  1101. }
  1102. private func animateOverlay(visible: Bool) {
  1103. let target: CGFloat = visible ? 1 : 0
  1104. NSAnimationContext.runAnimationGroup { context in
  1105. context.duration = 0.12
  1106. context.allowsImplicitAnimation = true
  1107. overlay.animator().alphaValue = target
  1108. }
  1109. }
  1110. private func applyBorder() {
  1111. if isSelected {
  1112. layer?.borderColor = palette.borderSelected.cgColor
  1113. layer?.borderWidth = 2
  1114. } else if isHovering {
  1115. layer?.borderColor = palette.borderHover.cgColor
  1116. layer?.borderWidth = 1
  1117. } else {
  1118. layer?.borderColor = palette.border.cgColor
  1119. layer?.borderWidth = 1
  1120. }
  1121. }
  1122. }
  1123. // MARK: - Mini preview renderer
  1124. /// Tiny stylized representation of a finished CV — accent strip, headline area,
  1125. /// faux paragraph + section lines. Adapts to the template's headline, accent,
  1126. /// sidebar, and section-label style so the grid feels varied at a glance.
  1127. private final class CVTemplatePreviewView: NSView {
  1128. private let template: CVTemplate
  1129. private let palette: CVTemplateCard.Palette
  1130. private let paper = NSView()
  1131. init(template: CVTemplate, palette: CVTemplateCard.Palette) {
  1132. self.template = template
  1133. self.palette = palette
  1134. super.init(frame: .zero)
  1135. wantsLayer = true
  1136. translatesAutoresizingMaskIntoConstraints = false
  1137. configurePaper()
  1138. }
  1139. @available(*, unavailable)
  1140. required init?(coder: NSCoder) {
  1141. fatalError("init(coder:) has not been implemented")
  1142. }
  1143. private func configurePaper() {
  1144. paper.translatesAutoresizingMaskIntoConstraints = false
  1145. paper.wantsLayer = true
  1146. paper.layer?.backgroundColor = palette.previewPaper.cgColor
  1147. paper.layer?.cornerRadius = 4
  1148. paper.layer?.borderColor = NSColor(srgbRed: 232 / 255, green: 235 / 255, blue: 241 / 255, alpha: 1).cgColor
  1149. paper.layer?.borderWidth = 1
  1150. paper.layer?.masksToBounds = true
  1151. addSubview(paper)
  1152. NSLayoutConstraint.activate([
  1153. paper.topAnchor.constraint(equalTo: topAnchor),
  1154. paper.bottomAnchor.constraint(equalTo: bottomAnchor),
  1155. paper.centerXAnchor.constraint(equalTo: centerXAnchor),
  1156. paper.widthAnchor.constraint(equalTo: heightAnchor, multiplier: 0.78),
  1157. paper.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor),
  1158. paper.trailingAnchor.constraint(lessThanOrEqualTo: trailingAnchor)
  1159. ])
  1160. let header = makeHeader()
  1161. let body = makeBody()
  1162. let stack = NSStackView(views: [header, body])
  1163. stack.orientation = .vertical
  1164. stack.alignment = .leading
  1165. stack.spacing = 6
  1166. stack.distribution = .fill
  1167. stack.translatesAutoresizingMaskIntoConstraints = false
  1168. paper.addSubview(stack)
  1169. NSLayoutConstraint.activate([
  1170. stack.leadingAnchor.constraint(equalTo: paper.leadingAnchor, constant: 8),
  1171. stack.trailingAnchor.constraint(equalTo: paper.trailingAnchor, constant: -8),
  1172. stack.topAnchor.constraint(equalTo: paper.topAnchor, constant: 8),
  1173. stack.bottomAnchor.constraint(lessThanOrEqualTo: paper.bottomAnchor, constant: -8),
  1174. header.widthAnchor.constraint(equalTo: stack.widthAnchor),
  1175. body.widthAnchor.constraint(equalTo: stack.widthAnchor)
  1176. ])
  1177. }
  1178. // MARK: Header
  1179. private func makeHeader() -> NSView {
  1180. let container = NSView()
  1181. container.translatesAutoresizingMaskIntoConstraints = false
  1182. let jitterA = templateVisualJitter(template.id)
  1183. let jitterB = templateVisualJitter(template.id + "-b")
  1184. let nameInk = palette.previewInk.blended(withFraction: CGFloat(jitterA * 0.14), of: palette.previewAccentBlue) ?? palette.previewInk
  1185. let nameStrip = makeLine(color: nameInk, height: 5.2 + CGFloat(jitterB * 0.9), widthFraction: 0.52 + CGFloat(jitterA * 0.14))
  1186. let roleStrip = makeLine(color: palette.previewMuted, height: 3, widthFraction: 0.36 + CGFloat(jitterB * 0.12))
  1187. let contactStrip = makeLine(color: palette.previewMuted.withAlphaComponent(0.7), height: 2, widthFraction: 0.48 + CGFloat(jitterA * 0.1))
  1188. let textStack = NSStackView(views: [nameStrip, roleStrip, contactStrip])
  1189. textStack.orientation = .vertical
  1190. textStack.spacing = 4
  1191. textStack.translatesAutoresizingMaskIntoConstraints = false
  1192. switch template.headline {
  1193. case .centered:
  1194. textStack.alignment = .centerX
  1195. case .leftAligned, .leftWithInitials:
  1196. textStack.alignment = .leading
  1197. case .avatarStacked:
  1198. textStack.alignment = .leading
  1199. }
  1200. container.addSubview(textStack)
  1201. switch template.headline {
  1202. case .leftWithInitials:
  1203. let avatar = makeAvatar()
  1204. container.addSubview(avatar)
  1205. NSLayoutConstraint.activate([
  1206. textStack.leadingAnchor.constraint(equalTo: container.leadingAnchor),
  1207. textStack.trailingAnchor.constraint(lessThanOrEqualTo: avatar.leadingAnchor, constant: -6),
  1208. textStack.topAnchor.constraint(equalTo: container.topAnchor),
  1209. textStack.bottomAnchor.constraint(equalTo: container.bottomAnchor),
  1210. avatar.trailingAnchor.constraint(equalTo: container.trailingAnchor),
  1211. avatar.centerYAnchor.constraint(equalTo: container.centerYAnchor),
  1212. avatar.widthAnchor.constraint(equalToConstant: 20),
  1213. avatar.heightAnchor.constraint(equalToConstant: 20)
  1214. ])
  1215. case .avatarStacked:
  1216. let avatar = makeAvatar()
  1217. container.addSubview(avatar)
  1218. NSLayoutConstraint.activate([
  1219. avatar.topAnchor.constraint(equalTo: container.topAnchor),
  1220. avatar.leadingAnchor.constraint(equalTo: container.leadingAnchor),
  1221. avatar.widthAnchor.constraint(equalToConstant: 22),
  1222. avatar.heightAnchor.constraint(equalToConstant: 22),
  1223. textStack.topAnchor.constraint(equalTo: avatar.bottomAnchor, constant: 4),
  1224. textStack.leadingAnchor.constraint(equalTo: container.leadingAnchor),
  1225. textStack.trailingAnchor.constraint(equalTo: container.trailingAnchor),
  1226. textStack.bottomAnchor.constraint(equalTo: container.bottomAnchor)
  1227. ])
  1228. case .centered:
  1229. NSLayoutConstraint.activate([
  1230. textStack.topAnchor.constraint(equalTo: container.topAnchor),
  1231. textStack.bottomAnchor.constraint(equalTo: container.bottomAnchor),
  1232. textStack.centerXAnchor.constraint(equalTo: container.centerXAnchor),
  1233. textStack.leadingAnchor.constraint(greaterThanOrEqualTo: container.leadingAnchor),
  1234. textStack.trailingAnchor.constraint(lessThanOrEqualTo: container.trailingAnchor)
  1235. ])
  1236. case .leftAligned:
  1237. NSLayoutConstraint.activate([
  1238. textStack.leadingAnchor.constraint(equalTo: container.leadingAnchor),
  1239. textStack.trailingAnchor.constraint(lessThanOrEqualTo: container.trailingAnchor),
  1240. textStack.topAnchor.constraint(equalTo: container.topAnchor),
  1241. textStack.bottomAnchor.constraint(equalTo: container.bottomAnchor)
  1242. ])
  1243. }
  1244. // Accent decorations
  1245. switch template.accent {
  1246. case .none:
  1247. break
  1248. case .redUnderline, .redBar:
  1249. let accent = NSView()
  1250. accent.translatesAutoresizingMaskIntoConstraints = false
  1251. accent.wantsLayer = true
  1252. accent.layer?.backgroundColor = palette.previewAccentRed.cgColor
  1253. container.addSubview(accent)
  1254. NSLayoutConstraint.activate([
  1255. accent.heightAnchor.constraint(equalToConstant: template.accent == .redBar ? 2.5 : 1.5),
  1256. accent.topAnchor.constraint(equalTo: textStack.bottomAnchor, constant: 5),
  1257. accent.leadingAnchor.constraint(equalTo: container.leadingAnchor),
  1258. accent.widthAnchor.constraint(equalTo: container.widthAnchor, multiplier: template.accent == .redBar ? 0.32 : 0.9),
  1259. accent.bottomAnchor.constraint(lessThanOrEqualTo: container.bottomAnchor)
  1260. ])
  1261. case .blueBar:
  1262. let accent = NSView()
  1263. accent.translatesAutoresizingMaskIntoConstraints = false
  1264. accent.wantsLayer = true
  1265. accent.layer?.backgroundColor = palette.previewAccentBlue.cgColor
  1266. container.addSubview(accent)
  1267. NSLayoutConstraint.activate([
  1268. accent.heightAnchor.constraint(equalToConstant: 2.5),
  1269. accent.topAnchor.constraint(equalTo: textStack.bottomAnchor, constant: 5),
  1270. accent.leadingAnchor.constraint(equalTo: container.leadingAnchor),
  1271. accent.widthAnchor.constraint(equalTo: container.widthAnchor, multiplier: 0.32),
  1272. accent.bottomAnchor.constraint(lessThanOrEqualTo: container.bottomAnchor)
  1273. ])
  1274. }
  1275. return container
  1276. }
  1277. /// Stable 0…1 value per template so thumbnails are not visually identical when metadata is similar.
  1278. private func templateVisualJitter(_ salt: String) -> Double {
  1279. var hash: UInt64 = 1469598103934665603
  1280. for b in salt.utf8 {
  1281. hash ^= UInt64(b)
  1282. hash &*= 1_099_511_628_211
  1283. }
  1284. return Double(hash % 10_007) / 10_006.0
  1285. }
  1286. private func makeAvatar() -> NSView {
  1287. let avatar = NSView()
  1288. avatar.translatesAutoresizingMaskIntoConstraints = false
  1289. avatar.wantsLayer = true
  1290. avatar.layer?.backgroundColor = palette.previewSidebarTint.cgColor
  1291. avatar.layer?.borderColor = palette.previewMuted.withAlphaComponent(0.4).cgColor
  1292. avatar.layer?.borderWidth = 1
  1293. avatar.layer?.cornerRadius = 11
  1294. let initials = NSTextField(labelWithString: "SJ")
  1295. initials.font = .systemFont(ofSize: 7, weight: .bold)
  1296. initials.textColor = palette.previewInk
  1297. initials.alignment = .center
  1298. initials.translatesAutoresizingMaskIntoConstraints = false
  1299. avatar.addSubview(initials)
  1300. NSLayoutConstraint.activate([
  1301. initials.centerXAnchor.constraint(equalTo: avatar.centerXAnchor),
  1302. initials.centerYAnchor.constraint(equalTo: avatar.centerYAnchor)
  1303. ])
  1304. return avatar
  1305. }
  1306. // MARK: Body
  1307. private func makeBody() -> NSView {
  1308. switch template.layout {
  1309. case .singleColumn:
  1310. return makeColumn(width: nil, isSidebar: false)
  1311. case .twoColumn(let side, let tinted):
  1312. return makeTwoColumnLayout(sidebarSide: side, tinted: tinted)
  1313. }
  1314. }
  1315. private func makeTwoColumnLayout(sidebarSide: CVTemplate.SidebarSide, tinted: Bool) -> NSView {
  1316. let container = NSView()
  1317. container.translatesAutoresizingMaskIntoConstraints = false
  1318. let sidebar = makeColumn(width: nil, isSidebar: true)
  1319. if tinted {
  1320. sidebar.wantsLayer = true
  1321. sidebar.layer?.backgroundColor = palette.previewSidebarTint.cgColor
  1322. sidebar.layer?.cornerRadius = 3
  1323. }
  1324. let main = makeColumn(width: nil, isSidebar: false)
  1325. container.addSubview(sidebar)
  1326. container.addSubview(main)
  1327. let leadingItem: NSView = (sidebarSide == .leading) ? sidebar : main
  1328. let trailingItem: NSView = (sidebarSide == .leading) ? main : sidebar
  1329. NSLayoutConstraint.activate([
  1330. leadingItem.leadingAnchor.constraint(equalTo: container.leadingAnchor),
  1331. leadingItem.topAnchor.constraint(equalTo: container.topAnchor, constant: 2),
  1332. leadingItem.bottomAnchor.constraint(lessThanOrEqualTo: container.bottomAnchor),
  1333. trailingItem.trailingAnchor.constraint(equalTo: container.trailingAnchor),
  1334. trailingItem.topAnchor.constraint(equalTo: container.topAnchor, constant: 2),
  1335. trailingItem.bottomAnchor.constraint(lessThanOrEqualTo: container.bottomAnchor),
  1336. trailingItem.leadingAnchor.constraint(equalTo: leadingItem.trailingAnchor, constant: 8),
  1337. sidebar.widthAnchor.constraint(equalTo: container.widthAnchor, multiplier: 0.32),
  1338. main.widthAnchor.constraint(equalTo: container.widthAnchor, multiplier: 0.6)
  1339. ])
  1340. return container
  1341. }
  1342. private func makeColumn(width: CGFloat?, isSidebar: Bool) -> NSView {
  1343. let stack = NSStackView()
  1344. stack.orientation = .vertical
  1345. stack.alignment = .leading
  1346. stack.spacing = 6
  1347. stack.translatesAutoresizingMaskIntoConstraints = false
  1348. let sectionNames: [String] = isSidebar
  1349. ? ["CONTACT", "SKILLS", "LANGUAGES", "INTERESTS"]
  1350. : ["PROFILE", "EXPERIENCE", "EDUCATION", "SKILLS"]
  1351. for (i, section) in sectionNames.enumerated() {
  1352. let block = makeSectionBlock(title: section, lineCount: isSidebar ? 3 : (i == 1 ? 4 : 2), narrow: isSidebar)
  1353. stack.addArrangedSubview(block)
  1354. block.widthAnchor.constraint(equalTo: stack.widthAnchor).isActive = true
  1355. }
  1356. return stack
  1357. }
  1358. private func makeSectionBlock(title: String, lineCount: Int, narrow: Bool) -> NSView {
  1359. let label = NSTextField(labelWithString: formattedSectionLabel(title))
  1360. label.font = .systemFont(ofSize: narrow ? 5 : 5.5, weight: .bold)
  1361. label.textColor = palette.previewAccentBlue.blended(withFraction: 0.4, of: palette.previewInk) ?? palette.previewInk
  1362. label.maximumNumberOfLines = 1
  1363. label.isBordered = false
  1364. label.drawsBackground = false
  1365. label.isEditable = false
  1366. label.isSelectable = false
  1367. label.translatesAutoresizingMaskIntoConstraints = false
  1368. let lines = NSStackView()
  1369. lines.orientation = .vertical
  1370. lines.alignment = .leading
  1371. lines.spacing = 2
  1372. lines.translatesAutoresizingMaskIntoConstraints = false
  1373. for index in 0..<lineCount {
  1374. let widthFraction: CGFloat = max(0.4, 0.95 - CGFloat(index) * 0.13)
  1375. let line = makeLine(color: palette.previewMuted.withAlphaComponent(0.65), height: 1.6, widthFraction: widthFraction)
  1376. lines.addArrangedSubview(line)
  1377. line.widthAnchor.constraint(equalTo: lines.widthAnchor, multiplier: widthFraction).isActive = true
  1378. }
  1379. let block = NSStackView(views: [label, lines])
  1380. block.orientation = .vertical
  1381. block.alignment = .leading
  1382. block.spacing = 2
  1383. block.translatesAutoresizingMaskIntoConstraints = false
  1384. let blockWidth = block.widthAnchor
  1385. lines.widthAnchor.constraint(equalTo: blockWidth).isActive = true
  1386. return block
  1387. }
  1388. private func formattedSectionLabel(_ raw: String) -> String {
  1389. switch template.sectionLabelStyle {
  1390. case .uppercase: return raw
  1391. case .slashed: return "// \(raw.capitalized)"
  1392. case .bracketed: return "[ \(raw) ]"
  1393. }
  1394. }
  1395. private func makeLine(color: NSColor, height: CGFloat, widthFraction: CGFloat) -> NSView {
  1396. let line = LineView()
  1397. line.translatesAutoresizingMaskIntoConstraints = false
  1398. line.wantsLayer = true
  1399. line.layer?.backgroundColor = color.cgColor
  1400. line.layer?.cornerRadius = max(height / 2, 1)
  1401. line.heightAnchor.constraint(equalToConstant: height).isActive = true
  1402. line.widthFraction = widthFraction
  1403. return line
  1404. }
  1405. }
  1406. private final class LineView: NSView {
  1407. var widthFraction: CGFloat = 1
  1408. }
  1409. // MARK: - Helpers
  1410. /// Flipped origin so the grid stacks fill from the top.
  1411. private final class TopFlippedView: NSView {
  1412. override var isFlipped: Bool { true }
  1413. }
  1414. /// Local copy of the dashboard's hoverable button so this file stays
  1415. /// self-contained without exposing the existing private classes.
  1416. private final class CVHoverableButton: NSButton {
  1417. var hoverHandler: ((Bool) -> Void)?
  1418. var pointerCursor: Bool = false
  1419. private(set) var isHovering: Bool = false
  1420. private var trackingArea: NSTrackingArea?
  1421. private var didPushCursor: Bool = false
  1422. override func updateTrackingAreas() {
  1423. super.updateTrackingAreas()
  1424. if let area = trackingArea { removeTrackingArea(area) }
  1425. let area = NSTrackingArea(
  1426. rect: bounds,
  1427. options: [.activeInKeyWindow, .mouseEnteredAndExited, .inVisibleRect],
  1428. owner: self,
  1429. userInfo: nil
  1430. )
  1431. addTrackingArea(area)
  1432. trackingArea = area
  1433. }
  1434. override func mouseEntered(with event: NSEvent) {
  1435. super.mouseEntered(with: event)
  1436. isHovering = true
  1437. hoverHandler?(true)
  1438. if pointerCursor, !didPushCursor {
  1439. NSCursor.pointingHand.push()
  1440. didPushCursor = true
  1441. }
  1442. }
  1443. override func mouseExited(with event: NSEvent) {
  1444. super.mouseExited(with: event)
  1445. isHovering = false
  1446. hoverHandler?(false)
  1447. if didPushCursor {
  1448. NSCursor.pop()
  1449. didPushCursor = false
  1450. }
  1451. }
  1452. override func viewWillMove(toWindow newWindow: NSWindow?) {
  1453. super.viewWillMove(toWindow: newWindow)
  1454. if newWindow == nil, didPushCursor {
  1455. NSCursor.pop()
  1456. didPushCursor = false
  1457. isHovering = false
  1458. }
  1459. }
  1460. }