Geen omschrijving

CVProfileDocumentView.swift 58KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. //
  2. // CVProfileDocumentView.swift
  3. // App for Indeed
  4. //
  5. // Renders saved profile data in a layout that follows the selected CV template’s
  6. // family (professional / modern / minimal / executive / creative), headline,
  7. // accent, section labels, and column structure.
  8. //
  9. import Cocoa
  10. /// Typography and chrome derived from `CVTemplate.family` so the filled résumé
  11. /// visibly matches the gallery card the user picked—not a single generic layout.
  12. private struct DocumentStyle {
  13. let nameFont: NSFont
  14. let roleFont: NSFont
  15. let contactFont: NSFont
  16. let sectionFont: NSFont
  17. let bodyFont: NSFont
  18. let bodyCompactFont: NSFont
  19. let expTitleFont: NSFont
  20. let expMetaFont: NSFont
  21. let eduTitleFont: NSFont
  22. let eduMetaFont: NSFont
  23. let bulletBodyFont: NSFont
  24. let bulletMarkerFont: NSFont
  25. let bulletMarkerColor: NSColor
  26. let ink: NSColor
  27. let muted: NSColor
  28. let rule: NSColor
  29. let cardBackground: NSColor
  30. let columnVerticalSpacing: CGFloat
  31. let bodyBlockSpacing: CGFloat
  32. /// When true, the headline job title uses the template theme color.
  33. let roleUsesThemeColor: Bool
  34. /// Section heading text color (often theme; executive stays conservative).
  35. let sectionInk: NSColor
  36. static func make(for template: CVTemplate) -> DocumentStyle {
  37. let theme = template.themeColor
  38. switch template.family {
  39. case .minimal:
  40. return DocumentStyle(
  41. nameFont: .systemFont(ofSize: 20, weight: .regular),
  42. roleFont: .systemFont(ofSize: 13.5, weight: .regular),
  43. contactFont: .systemFont(ofSize: 11.5, weight: .regular),
  44. sectionFont: .systemFont(ofSize: 10.5, weight: .semibold),
  45. bodyFont: .systemFont(ofSize: 12.5, weight: .regular),
  46. bodyCompactFont: .systemFont(ofSize: 12, weight: .regular),
  47. expTitleFont: .systemFont(ofSize: 13, weight: .medium),
  48. expMetaFont: .systemFont(ofSize: 11.5, weight: .regular),
  49. eduTitleFont: .systemFont(ofSize: 13, weight: .medium),
  50. eduMetaFont: .systemFont(ofSize: 11.5, weight: .regular),
  51. bulletBodyFont: .systemFont(ofSize: 12, weight: .regular),
  52. bulletMarkerFont: .systemFont(ofSize: 11, weight: .light),
  53. bulletMarkerColor: theme.withAlphaComponent(0.55),
  54. ink: NSColor(srgbRed: 42 / 255, green: 48 / 255, blue: 56 / 255, alpha: 1),
  55. muted: NSColor(srgbRed: 110 / 255, green: 118 / 255, blue: 128 / 255, alpha: 1),
  56. rule: NSColor(srgbRed: 228 / 255, green: 230 / 255, blue: 234 / 255, alpha: 1),
  57. cardBackground: NSColor(srgbRed: 0.998, green: 0.998, blue: 0.998, alpha: 1),
  58. columnVerticalSpacing: 15,
  59. bodyBlockSpacing: 15,
  60. roleUsesThemeColor: false,
  61. sectionInk: theme.withAlphaComponent(0.92)
  62. )
  63. case .professional:
  64. return DocumentStyle(
  65. nameFont: .systemFont(ofSize: 21, weight: .semibold),
  66. roleFont: .systemFont(ofSize: 13.5, weight: .medium),
  67. contactFont: .systemFont(ofSize: 11.5, weight: .regular),
  68. sectionFont: .systemFont(ofSize: 10.5, weight: .heavy),
  69. bodyFont: .systemFont(ofSize: 12, weight: .regular),
  70. bodyCompactFont: .systemFont(ofSize: 11.5, weight: .regular),
  71. expTitleFont: .systemFont(ofSize: 13.5, weight: .semibold),
  72. expMetaFont: .systemFont(ofSize: 11.5, weight: .semibold),
  73. eduTitleFont: .systemFont(ofSize: 13, weight: .semibold),
  74. eduMetaFont: .systemFont(ofSize: 11.5, weight: .medium),
  75. bulletBodyFont: .systemFont(ofSize: 12, weight: .regular),
  76. bulletMarkerFont: .systemFont(ofSize: 12, weight: .bold),
  77. bulletMarkerColor: NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 0.55),
  78. ink: NSColor(srgbRed: 28 / 255, green: 36 / 255, blue: 48 / 255, alpha: 1),
  79. muted: NSColor(srgbRed: 88 / 255, green: 98 / 255, blue: 118 / 255, alpha: 1),
  80. rule: NSColor(srgbRed: 210 / 255, green: 218 / 255, blue: 232 / 255, alpha: 1),
  81. cardBackground: NSColor.white,
  82. columnVerticalSpacing: 13,
  83. bodyBlockSpacing: 13,
  84. roleUsesThemeColor: false,
  85. sectionInk: theme
  86. )
  87. case .modern:
  88. return DocumentStyle(
  89. nameFont: .systemFont(ofSize: 22, weight: .bold),
  90. roleFont: .systemFont(ofSize: 14, weight: .semibold),
  91. contactFont: .systemFont(ofSize: 12, weight: .regular),
  92. sectionFont: .systemFont(ofSize: 11, weight: .heavy),
  93. bodyFont: .systemFont(ofSize: 12.5, weight: .regular),
  94. bodyCompactFont: .systemFont(ofSize: 12, weight: .regular),
  95. expTitleFont: .systemFont(ofSize: 14, weight: .bold),
  96. expMetaFont: .systemFont(ofSize: 12, weight: .medium),
  97. eduTitleFont: .systemFont(ofSize: 13.5, weight: .bold),
  98. eduMetaFont: .systemFont(ofSize: 12, weight: .regular),
  99. bulletBodyFont: .systemFont(ofSize: 12.5, weight: .regular),
  100. bulletMarkerFont: .systemFont(ofSize: 13, weight: .bold),
  101. bulletMarkerColor: theme,
  102. ink: NSColor(srgbRed: 24 / 255, green: 34 / 255, blue: 52 / 255, alpha: 1),
  103. muted: NSColor(srgbRed: 96 / 255, green: 110 / 255, blue: 132 / 255, alpha: 1),
  104. rule: NSColor(srgbRed: 200 / 255, green: 214 / 255, blue: 236 / 255, alpha: 1),
  105. cardBackground: NSColor(srgbRed: 0.99, green: 0.995, blue: 1, alpha: 1),
  106. columnVerticalSpacing: 17,
  107. bodyBlockSpacing: 16,
  108. roleUsesThemeColor: true,
  109. sectionInk: theme
  110. )
  111. case .executive:
  112. let serifName = NSFont(name: "Georgia-Bold", size: 23) ?? .systemFont(ofSize: 23, weight: .semibold)
  113. let serifRole = NSFont(name: "Georgia", size: 14) ?? .systemFont(ofSize: 14, weight: .regular)
  114. let serifBody = NSFont(name: "Georgia", size: 12.5) ?? .systemFont(ofSize: 12.5, weight: .regular)
  115. let serifCompact = NSFont(name: "Georgia", size: 12) ?? .systemFont(ofSize: 12, weight: .regular)
  116. let georgia12 = NSFont(name: "Georgia", size: 12) ?? .systemFont(ofSize: 12)
  117. let georgia115 = NSFont(name: "Georgia", size: 11.5) ?? .systemFont(ofSize: 11.5)
  118. let expMeta = NSFont(name: "Georgia-Italic", size: 12)
  119. ?? NSFontManager.shared.convert(georgia12, toHaveTrait: .italicFontMask)
  120. let eduMeta = NSFont(name: "Georgia-Italic", size: 11.5)
  121. ?? NSFontManager.shared.convert(georgia115, toHaveTrait: .italicFontMask)
  122. return DocumentStyle(
  123. nameFont: serifName,
  124. roleFont: serifRole,
  125. contactFont: NSFont(name: "Georgia", size: 11.5) ?? .systemFont(ofSize: 11.5),
  126. sectionFont: .systemFont(ofSize: 10.5, weight: .heavy),
  127. bodyFont: serifBody,
  128. bodyCompactFont: serifCompact,
  129. expTitleFont: NSFont(name: "Georgia-Bold", size: 14) ?? .systemFont(ofSize: 14, weight: .semibold),
  130. expMetaFont: expMeta,
  131. eduTitleFont: NSFont(name: "Georgia-Bold", size: 13.5) ?? .systemFont(ofSize: 13.5, weight: .semibold),
  132. eduMetaFont: eduMeta,
  133. bulletBodyFont: serifCompact,
  134. bulletMarkerFont: .systemFont(ofSize: 11, weight: .bold),
  135. bulletMarkerColor: NSColor(srgbRed: 55 / 255, green: 55 / 255, blue: 62 / 255, alpha: 1),
  136. ink: NSColor(srgbRed: 22 / 255, green: 22 / 255, blue: 28 / 255, alpha: 1),
  137. muted: NSColor(srgbRed: 82 / 255, green: 82 / 255, blue: 90 / 255, alpha: 1),
  138. rule: NSColor(srgbRed: 72 / 255, green: 72 / 255, blue: 78 / 255, alpha: 0.35),
  139. cardBackground: NSColor(srgbRed: 0.992, green: 0.99, blue: 0.985, alpha: 1),
  140. columnVerticalSpacing: 18,
  141. bodyBlockSpacing: 17,
  142. roleUsesThemeColor: false,
  143. sectionInk: NSColor(srgbRed: 32 / 255, green: 32 / 255, blue: 38 / 255, alpha: 1)
  144. )
  145. case .creative:
  146. return DocumentStyle(
  147. nameFont: .systemFont(ofSize: 23, weight: .heavy),
  148. roleFont: .systemFont(ofSize: 14, weight: .semibold),
  149. contactFont: .systemFont(ofSize: 11.5, weight: .medium),
  150. sectionFont: .systemFont(ofSize: 11.5, weight: .heavy),
  151. bodyFont: .systemFont(ofSize: 12.5, weight: .regular),
  152. bodyCompactFont: .systemFont(ofSize: 12, weight: .regular),
  153. expTitleFont: .systemFont(ofSize: 14, weight: .heavy),
  154. expMetaFont: .systemFont(ofSize: 12, weight: .semibold),
  155. eduTitleFont: .systemFont(ofSize: 13.5, weight: .heavy),
  156. eduMetaFont: .systemFont(ofSize: 12, weight: .medium),
  157. bulletBodyFont: .systemFont(ofSize: 12.5, weight: .regular),
  158. bulletMarkerFont: .systemFont(ofSize: 13, weight: .heavy),
  159. bulletMarkerColor: NSColor(srgbRed: 207 / 255, green: 67 / 255, blue: 50 / 255, alpha: 1),
  160. ink: NSColor(srgbRed: 32 / 255, green: 26 / 255, blue: 52 / 255, alpha: 1),
  161. muted: NSColor(srgbRed: 108 / 255, green: 96 / 255, blue: 130 / 255, alpha: 1),
  162. rule: theme.withAlphaComponent(0.22),
  163. cardBackground: NSColor(srgbRed: 0.995, green: 0.993, blue: 1, alpha: 1),
  164. columnVerticalSpacing: 18,
  165. bodyBlockSpacing: 17,
  166. roleUsesThemeColor: true,
  167. sectionInk: NSColor(srgbRed: 207 / 255, green: 67 / 255, blue: 50 / 255, alpha: 1)
  168. )
  169. }
  170. }
  171. }
  172. /// Full-width résumé layout that injects `SavedProfile` into the visual language of `CVTemplate`.
  173. final class CVProfileDocumentView: NSView {
  174. private let profile: SavedProfile
  175. private let template: CVTemplate
  176. private let style: DocumentStyle
  177. /// Matches `CVTemplatePreviewView` so the same template id + layout recipe renders the same silhouette as the gallery card.
  178. private let variant: Int
  179. private let isEditable: Bool
  180. init(profile: SavedProfile, template: CVTemplate, isEditable: Bool = false) {
  181. self.profile = profile
  182. self.template = template
  183. self.style = DocumentStyle.make(for: template)
  184. self.variant = template.galleryLayoutVariant
  185. self.isEditable = isEditable
  186. super.init(frame: .zero)
  187. translatesAutoresizingMaskIntoConstraints = false
  188. wantsLayer = true
  189. layer?.backgroundColor = NSColor.clear.cgColor
  190. userInterfaceLayoutDirection = .leftToRight
  191. let card = NSView()
  192. card.translatesAutoresizingMaskIntoConstraints = false
  193. card.wantsLayer = true
  194. card.layer?.backgroundColor = style.cardBackground.cgColor
  195. card.layer?.cornerRadius = template.family == .executive ? 6 : 10
  196. card.layer?.borderWidth = 1
  197. card.layer?.borderColor = style.rule.cgColor
  198. card.layer?.masksToBounds = true
  199. let root = buildRoot()
  200. root.translatesAutoresizingMaskIntoConstraints = false
  201. card.addSubview(root)
  202. addSubview(card)
  203. NSLayoutConstraint.activate([
  204. card.leadingAnchor.constraint(equalTo: leadingAnchor),
  205. card.trailingAnchor.constraint(equalTo: trailingAnchor),
  206. card.topAnchor.constraint(equalTo: topAnchor),
  207. card.bottomAnchor.constraint(equalTo: bottomAnchor),
  208. card.widthAnchor.constraint(equalToConstant: 640),
  209. root.leadingAnchor.constraint(equalTo: card.leadingAnchor, constant: 36),
  210. root.trailingAnchor.constraint(equalTo: card.trailingAnchor, constant: -36),
  211. root.topAnchor.constraint(equalTo: card.topAnchor, constant: 32),
  212. root.bottomAnchor.constraint(equalTo: card.bottomAnchor, constant: -36)
  213. ])
  214. }
  215. @available(*, unavailable)
  216. required init?(coder: NSCoder) {
  217. fatalError("init(coder:) has not been implemented")
  218. }
  219. // MARK: - Composition
  220. private func buildRoot() -> NSView {
  221. switch template.family {
  222. case .modern:
  223. return buildModernFamilyDocument()
  224. case .creative:
  225. return buildCreativeFamilyDocument()
  226. case .professional, .minimal, .executive:
  227. return buildTraditionalFamilyDocument()
  228. }
  229. }
  230. // MARK: - Modern (gallery uses three distinct silhouettes from `variant`)
  231. private func buildModernFamilyDocument() -> NSView {
  232. switch variant % 3 {
  233. case 0: return modernClassicBandDocument()
  234. case 1: return modernRailDocument()
  235. default: return modernSplitHeaderDocument()
  236. }
  237. }
  238. private func modernClassicBandDocument() -> NSView {
  239. let theme = template.themeColor
  240. let white = NSColor.white
  241. let nameText = displayable(profile.personal.fullName, placeholder: "Your name")
  242. let roleText = displayable(profile.personal.jobTitle, placeholder: "Professional headline")
  243. let header = NSView()
  244. header.translatesAutoresizingMaskIntoConstraints = false
  245. header.wantsLayer = true
  246. header.layer?.backgroundColor = theme.cgColor
  247. header.layer?.cornerRadius = variant % 2 == 0 ? 8 : 6
  248. let name = label(nameText, font: .systemFont(ofSize: 22, weight: .bold), color: white, maxLines: 2)
  249. let role = label(roleText, font: .systemFont(ofSize: 14, weight: .medium), color: white.withAlphaComponent(0.92), maxLines: 2)
  250. let textCol = NSStackView(views: [name, role])
  251. textCol.orientation = .vertical
  252. textCol.spacing = 4
  253. textCol.alignment = .leading
  254. textCol.translatesAutoresizingMaskIntoConstraints = false
  255. let iconRow = NSStackView()
  256. iconRow.orientation = .horizontal
  257. iconRow.spacing = 10
  258. iconRow.translatesAutoresizingMaskIntoConstraints = false
  259. for sym in ["mappin.and.ellipse", "phone.fill", "envelope.fill"] {
  260. guard let img = NSImage(systemSymbolName: sym, accessibilityDescription: nil) else { continue }
  261. let iv = NSImageView(image: img)
  262. iv.symbolConfiguration = NSImage.SymbolConfiguration(pointSize: 13, weight: .semibold)
  263. iv.contentTintColor = white.withAlphaComponent(0.88)
  264. iconRow.addArrangedSubview(iv)
  265. }
  266. let topRow = NSStackView()
  267. topRow.orientation = .horizontal
  268. topRow.spacing = 14
  269. topRow.alignment = .centerY
  270. topRow.translatesAutoresizingMaskIntoConstraints = false
  271. topRow.addArrangedSubview(textCol)
  272. topRow.addArrangedSubview(NSView())
  273. topRow.addArrangedSubview(iconRow)
  274. header.addSubview(topRow)
  275. NSLayoutConstraint.activate([
  276. topRow.leadingAnchor.constraint(equalTo: header.leadingAnchor, constant: 18),
  277. topRow.trailingAnchor.constraint(equalTo: header.trailingAnchor, constant: -18),
  278. topRow.topAnchor.constraint(equalTo: header.topAnchor, constant: 14),
  279. topRow.bottomAnchor.constraint(equalTo: header.bottomAnchor, constant: -14)
  280. ])
  281. let body: NSView
  282. switch template.layout {
  283. case .singleColumn:
  284. body = modernMainContentColumn(compact: false, includeSummaryInMain: true)
  285. case .twoColumn(let side, let tinted):
  286. let main = modernMainContentColumn(compact: true, includeSummaryInMain: false)
  287. let sideCol = modernAboutHighlightsSidebar(tinted: tinted)
  288. let row = NSStackView()
  289. row.orientation = .horizontal
  290. row.spacing = 20
  291. row.alignment = .top
  292. row.translatesAutoresizingMaskIntoConstraints = false
  293. let mult: CGFloat = (variant % 4 == 2) ? 0.36 : 0.32
  294. if side == .leading {
  295. row.addArrangedSubview(sideCol)
  296. row.addArrangedSubview(main)
  297. sideCol.widthAnchor.constraint(equalTo: row.widthAnchor, multiplier: mult).isActive = true
  298. } else {
  299. row.addArrangedSubview(main)
  300. row.addArrangedSubview(sideCol)
  301. sideCol.widthAnchor.constraint(equalTo: row.widthAnchor, multiplier: mult).isActive = true
  302. }
  303. body = row
  304. }
  305. let wrap = NSStackView(views: [header, body])
  306. wrap.orientation = .vertical
  307. wrap.spacing = 18
  308. wrap.alignment = .leading
  309. return wrap
  310. }
  311. private func modernRailDocument() -> NSView {
  312. let theme = template.themeColor
  313. let rail = NSView()
  314. rail.translatesAutoresizingMaskIntoConstraints = false
  315. rail.wantsLayer = true
  316. rail.layer?.backgroundColor = theme.cgColor
  317. rail.layer?.cornerRadius = 2
  318. rail.widthAnchor.constraint(equalToConstant: 3 + CGFloat(variant % 2)).isActive = true
  319. let inner = NSStackView()
  320. inner.orientation = .vertical
  321. inner.spacing = 10
  322. inner.alignment = .leading
  323. inner.translatesAutoresizingMaskIntoConstraints = false
  324. let nameText = displayable(profile.personal.fullName, placeholder: "Your name")
  325. let roleText = displayable(profile.personal.jobTitle, placeholder: "Professional headline")
  326. let contactParts = [profile.personal.email, profile.personal.phone].filter { !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }
  327. let contactLine = contactParts.isEmpty ? "Add contact in your profile" : contactParts.joined(separator: " · ")
  328. inner.addArrangedSubview(label(nameText, font: .systemFont(ofSize: 21, weight: .bold), color: style.ink, maxLines: 2))
  329. inner.addArrangedSubview(label(roleText, font: .systemFont(ofSize: 14, weight: .semibold), color: theme, maxLines: 2))
  330. inner.addArrangedSubview(label(contactLine, font: style.contactFont, color: style.muted, maxLines: 2))
  331. inner.addArrangedSubview(hairline())
  332. inner.addArrangedSubview(skillTagRow(theme: theme, maxTags: 5))
  333. inner.addArrangedSubview(modernPrimaryBody(theme: theme))
  334. let row = NSStackView(views: [rail, inner])
  335. row.orientation = .horizontal
  336. row.spacing = 14
  337. row.alignment = .top
  338. return row
  339. }
  340. private func modernSplitHeaderDocument() -> NSView {
  341. let theme = template.themeColor
  342. let nameText = displayable(profile.personal.fullName, placeholder: "Your name")
  343. let roleText = displayable(profile.personal.jobTitle, placeholder: "Professional headline")
  344. let loc = profile.personal.address.trimmingCharacters(in: .whitespacesAndNewlines)
  345. let left = NSStackView()
  346. left.orientation = .vertical
  347. left.spacing = 5
  348. left.alignment = .leading
  349. left.addArrangedSubview(label(nameText, font: .systemFont(ofSize: 21, weight: .bold), color: style.ink, maxLines: 2))
  350. left.addArrangedSubview(label(roleText, font: .systemFont(ofSize: 13.5, weight: .medium), color: style.muted, maxLines: 2))
  351. if !loc.isEmpty {
  352. left.addArrangedSubview(label(loc, font: style.contactFont, color: style.muted.withAlphaComponent(0.88), maxLines: 2))
  353. }
  354. let right = NSStackView()
  355. right.orientation = .vertical
  356. right.spacing = 8
  357. right.alignment = .leading
  358. right.wantsLayer = true
  359. right.layer?.backgroundColor = theme.cgColor
  360. right.layer?.cornerRadius = 8
  361. right.edgeInsets = NSEdgeInsets(top: 14, left: 14, bottom: 14, right: 14)
  362. let onW = NSColor.white
  363. if !profile.personal.email.isEmpty {
  364. right.addArrangedSubview(label(profile.personal.email, font: .systemFont(ofSize: 12, weight: .medium), color: onW.withAlphaComponent(0.95), maxLines: 2))
  365. }
  366. if !profile.personal.phone.isEmpty {
  367. right.addArrangedSubview(label(profile.personal.phone, font: .systemFont(ofSize: 12, weight: .medium), color: onW.withAlphaComponent(0.92), maxLines: 1))
  368. }
  369. if !loc.isEmpty {
  370. right.addArrangedSubview(label(loc, font: .systemFont(ofSize: 11.5, weight: .regular), color: onW.withAlphaComponent(0.8), maxLines: 2))
  371. }
  372. let top = NSStackView(views: [left, right])
  373. top.orientation = .horizontal
  374. top.spacing = 16
  375. top.alignment = .top
  376. left.widthAnchor.constraint(equalTo: top.widthAnchor, multiplier: 0.54).isActive = true
  377. let col = NSStackView(views: [top, hairline(), modernPrimaryBody(theme: theme)])
  378. col.orientation = .vertical
  379. col.spacing = 16
  380. col.alignment = .leading
  381. return col
  382. }
  383. private func modernPrimaryBody(theme: NSColor) -> NSView {
  384. switch template.layout {
  385. case .singleColumn:
  386. return modernMainContentColumn(compact: false, includeSummaryInMain: true)
  387. case .twoColumn(let side, let tinted):
  388. let main = modernMainContentColumn(compact: true, includeSummaryInMain: false)
  389. let sideCol = modernAboutHighlightsSidebar(tinted: tinted)
  390. let row = NSStackView()
  391. row.orientation = .horizontal
  392. row.spacing = 20
  393. row.alignment = .top
  394. let mult: CGFloat = (variant % 4 == 2) ? 0.36 : 0.32
  395. if side == .leading {
  396. row.addArrangedSubview(sideCol)
  397. row.addArrangedSubview(main)
  398. sideCol.widthAnchor.constraint(equalTo: row.widthAnchor, multiplier: mult).isActive = true
  399. } else {
  400. row.addArrangedSubview(main)
  401. row.addArrangedSubview(sideCol)
  402. sideCol.widthAnchor.constraint(equalTo: row.widthAnchor, multiplier: mult).isActive = true
  403. }
  404. return row
  405. }
  406. }
  407. private func modernMainContentColumn(compact: Bool, includeSummaryInMain: Bool) -> NSView {
  408. let theme = template.themeColor
  409. let v = NSStackView()
  410. v.orientation = .vertical
  411. v.spacing = compact ? style.bodyBlockSpacing : style.bodyBlockSpacing + 2
  412. v.alignment = .leading
  413. if includeSummaryInMain, let summary = nonEmpty(profile.careerSummary) {
  414. v.addArrangedSubview(modernSectionRow(symbol: "person.crop.circle", title: "About", theme: theme))
  415. v.addArrangedSubview(paragraph(summary, compact: compact))
  416. }
  417. let jobs = profile.workExperiences.filter { !$0.isEffectivelyEmpty }
  418. if !jobs.isEmpty {
  419. v.addArrangedSubview(modernSectionRow(symbol: "briefcase.fill", title: "Experience", theme: theme))
  420. for (index, job) in jobs.enumerated() {
  421. v.addArrangedSubview(experienceBlock(job: job, compact: compact))
  422. if index == 0 {
  423. v.addArrangedSubview(skillTagRow(theme: theme, maxTags: 5))
  424. }
  425. }
  426. }
  427. let schools = profile.educations.filter { !$0.isEffectivelyEmpty }
  428. if !schools.isEmpty {
  429. v.addArrangedSubview(modernSectionRow(symbol: "graduationcap.fill", title: "Education", theme: theme))
  430. for edu in schools {
  431. v.addArrangedSubview(educationBlock(edu: edu, compact: compact))
  432. }
  433. }
  434. appendCertificatesInterestsReferrals(to: v, compact: compact)
  435. return v
  436. }
  437. private func modernAboutHighlightsSidebar(tinted: Bool) -> NSView {
  438. let theme = template.themeColor
  439. let box = NSStackView()
  440. box.orientation = .vertical
  441. box.spacing = 12
  442. box.alignment = .leading
  443. if tinted {
  444. box.wantsLayer = true
  445. box.layer?.backgroundColor = theme.withAlphaComponent(0.1).cgColor
  446. box.layer?.cornerRadius = 8
  447. box.edgeInsets = NSEdgeInsets(top: 14, left: 14, bottom: 14, right: 14)
  448. }
  449. if let summary = nonEmpty(profile.careerSummary) {
  450. box.addArrangedSubview(modernSectionRow(symbol: "person.crop.circle", title: "About", theme: theme))
  451. box.addArrangedSubview(paragraph(summary, compact: true))
  452. }
  453. if let hi = highlightsBodyText() {
  454. box.addArrangedSubview(modernSectionRow(symbol: "star.fill", title: "Highlights", theme: theme))
  455. box.addArrangedSubview(paragraph(hi, compact: true))
  456. }
  457. if box.arrangedSubviews.isEmpty {
  458. box.addArrangedSubview(modernSectionRow(symbol: "person.crop.circle", title: "About", theme: theme))
  459. box.addArrangedSubview(paragraph("Add a career summary or interests in your profile to populate this column.", compact: true))
  460. }
  461. return box
  462. }
  463. private func modernSectionRow(symbol: String, title: String, theme: NSColor) -> NSView {
  464. guard let img = NSImage(systemSymbolName: symbol, accessibilityDescription: nil) else {
  465. return sectionHeading(title)
  466. }
  467. let iv = NSImageView(image: img)
  468. iv.symbolConfiguration = NSImage.SymbolConfiguration(pointSize: 12, weight: .semibold)
  469. iv.contentTintColor = theme
  470. let t = label(title.uppercased(), font: style.sectionFont, color: style.sectionInk, maxLines: 1)
  471. let r = NSStackView(views: [iv, t])
  472. r.orientation = .horizontal
  473. r.spacing = 8
  474. r.alignment = .centerY
  475. return r
  476. }
  477. private func skillTagRow(theme: NSColor, maxTags: Int) -> NSView {
  478. let tags = skillTokensFromProfile(max: maxTags)
  479. guard !tags.isEmpty else { return NSView() }
  480. let row = NSStackView()
  481. row.orientation = .horizontal
  482. row.spacing = 8
  483. row.alignment = .centerY
  484. for s in tags {
  485. let tag = NSView()
  486. tag.wantsLayer = true
  487. tag.layer?.backgroundColor = theme.withAlphaComponent(0.14).cgColor
  488. tag.layer?.cornerRadius = 6
  489. tag.translatesAutoresizingMaskIntoConstraints = false
  490. let lab = label(s, font: .systemFont(ofSize: 11, weight: .semibold), color: theme.blended(withFraction: 0.35, of: style.ink) ?? style.ink, maxLines: 1)
  491. lab.alignment = .center
  492. lab.translatesAutoresizingMaskIntoConstraints = false
  493. tag.addSubview(lab)
  494. NSLayoutConstraint.activate([
  495. lab.leadingAnchor.constraint(equalTo: tag.leadingAnchor, constant: 10),
  496. lab.trailingAnchor.constraint(equalTo: tag.trailingAnchor, constant: -10),
  497. lab.topAnchor.constraint(equalTo: tag.topAnchor, constant: 5),
  498. lab.bottomAnchor.constraint(equalTo: tag.bottomAnchor, constant: -5)
  499. ])
  500. row.addArrangedSubview(tag)
  501. }
  502. return row
  503. }
  504. // MARK: - Creative (dark sidebar in gallery — match filled page)
  505. private func buildCreativeFamilyDocument() -> NSView {
  506. switch template.layout {
  507. case .singleColumn:
  508. return creativeSingleColumnDocument()
  509. case .twoColumn(let side, _):
  510. return creativeTwoColumnDocument(sidebar: side)
  511. }
  512. }
  513. private func creativeDeepBackground() -> NSColor {
  514. let theme = template.themeColor
  515. let navy = NSColor(srgbRed: 0.08, green: 0.1, blue: 0.18, alpha: 1)
  516. let plum = NSColor(srgbRed: 0.14, green: 0.07, blue: 0.24, alpha: 1)
  517. switch variant % 4 {
  518. case 0: return theme.blended(withFraction: 0.52, of: navy) ?? theme
  519. case 1: return theme.blended(withFraction: 0.7, of: NSColor.black) ?? theme
  520. case 2: return style.ink.blended(withFraction: 0.38, of: theme) ?? theme
  521. default: return theme.blended(withFraction: 0.4, of: plum) ?? theme
  522. }
  523. }
  524. private func creativeSingleColumnDocument() -> NSView {
  525. let theme = template.themeColor
  526. let nameText = displayable(profile.personal.fullName, placeholder: "Your name")
  527. let roleText = displayable(profile.personal.jobTitle, placeholder: "Professional headline")
  528. let banner = NSView()
  529. banner.translatesAutoresizingMaskIntoConstraints = false
  530. banner.wantsLayer = true
  531. banner.layer?.backgroundColor = theme.cgColor
  532. banner.layer?.cornerRadius = variant % 4 == 1 ? 8 : 6
  533. let inner = label(" \(nameText) · \(roleText) ", font: .systemFont(ofSize: 14, weight: .bold), color: .white, maxLines: 2)
  534. inner.translatesAutoresizingMaskIntoConstraints = false
  535. banner.addSubview(inner)
  536. NSLayoutConstraint.activate([
  537. inner.leadingAnchor.constraint(equalTo: banner.leadingAnchor, constant: 14),
  538. inner.trailingAnchor.constraint(lessThanOrEqualTo: banner.trailingAnchor, constant: -14),
  539. inner.topAnchor.constraint(equalTo: banner.topAnchor, constant: 12),
  540. inner.bottomAnchor.constraint(equalTo: banner.bottomAnchor, constant: -12)
  541. ])
  542. let main = creativeMainStack(theme: theme)
  543. let col = NSStackView(views: [banner, main])
  544. col.orientation = .vertical
  545. col.spacing = 16
  546. col.alignment = .leading
  547. return col
  548. }
  549. private func creativeTwoColumnDocument(sidebar: CVTemplate.SidebarSide) -> NSView {
  550. let theme = template.themeColor
  551. let deep = creativeDeepBackground()
  552. let onSidebar = NSColor.white.withAlphaComponent(0.95)
  553. let skillPrefix = (variant % 3 == 0) ? "• " : "▸ "
  554. let sidebarStack = NSStackView()
  555. sidebarStack.orientation = .vertical
  556. sidebarStack.spacing = 12
  557. sidebarStack.alignment = .leading
  558. sidebarStack.wantsLayer = true
  559. sidebarStack.layer?.backgroundColor = deep.cgColor
  560. sidebarStack.layer?.cornerRadius = variant % 2 == 0 ? 10 : 8
  561. sidebarStack.edgeInsets = NSEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
  562. let nm = displayable(profile.personal.fullName, placeholder: "Your name")
  563. let role = displayable(profile.personal.jobTitle, placeholder: "Professional headline")
  564. sidebarStack.addArrangedSubview(label(nm, font: .systemFont(ofSize: 18, weight: .bold), color: onSidebar, maxLines: 2))
  565. sidebarStack.addArrangedSubview(label(role, font: .systemFont(ofSize: 13, weight: .medium), color: onSidebar.withAlphaComponent(0.85), maxLines: 2))
  566. if !profile.personal.email.isEmpty {
  567. sidebarStack.addArrangedSubview(label(profile.personal.email, font: .systemFont(ofSize: 11.5), color: onSidebar.withAlphaComponent(0.82), maxLines: 2))
  568. }
  569. if !profile.personal.phone.isEmpty {
  570. sidebarStack.addArrangedSubview(label(profile.personal.phone, font: .systemFont(ofSize: 11.5), color: onSidebar.withAlphaComponent(0.82), maxLines: 1))
  571. }
  572. sidebarStack.addArrangedSubview(creativeSidebarHeading("STRENGTHS", onSidebar: onSidebar, accent: theme))
  573. for token in skillTokensFromProfile(max: 8) {
  574. sidebarStack.addArrangedSubview(label("\(skillPrefix)\(token)", font: .systemFont(ofSize: 12, weight: .semibold), color: onSidebar.withAlphaComponent(0.92), maxLines: 2))
  575. }
  576. let main = creativeMainStack(theme: theme)
  577. let row = NSStackView()
  578. row.orientation = .horizontal
  579. row.spacing = 18
  580. row.alignment = .top
  581. let sidebarMult = 0.32 + CGFloat(variant % 3) * 0.02
  582. if sidebar == .leading {
  583. row.addArrangedSubview(sidebarStack)
  584. row.addArrangedSubview(main)
  585. sidebarStack.widthAnchor.constraint(equalTo: row.widthAnchor, multiplier: sidebarMult).isActive = true
  586. } else {
  587. row.addArrangedSubview(main)
  588. row.addArrangedSubview(sidebarStack)
  589. sidebarStack.widthAnchor.constraint(equalTo: row.widthAnchor, multiplier: sidebarMult).isActive = true
  590. }
  591. return row
  592. }
  593. private func creativeSidebarHeading(_ raw: String, onSidebar: NSColor, accent: NSColor) -> NSView {
  594. let t = label(raw, font: .systemFont(ofSize: 10.5, weight: .heavy), color: onSidebar, maxLines: 1)
  595. let bar = NSView()
  596. bar.translatesAutoresizingMaskIntoConstraints = false
  597. bar.wantsLayer = true
  598. bar.layer?.backgroundColor = accent.cgColor
  599. bar.heightAnchor.constraint(equalToConstant: 2).isActive = true
  600. let c = NSStackView(views: [t, bar])
  601. c.orientation = .vertical
  602. c.spacing = 4
  603. c.alignment = .leading
  604. bar.leadingAnchor.constraint(equalTo: t.leadingAnchor).isActive = true
  605. bar.widthAnchor.constraint(equalToConstant: 72).isActive = true
  606. return c
  607. }
  608. private func creativeMainHeader(theme: NSColor) -> NSView {
  609. let v = NSView()
  610. v.translatesAutoresizingMaskIntoConstraints = false
  611. let stripe = NSView()
  612. stripe.translatesAutoresizingMaskIntoConstraints = false
  613. stripe.wantsLayer = true
  614. stripe.layer?.backgroundColor = theme.cgColor
  615. v.addSubview(stripe)
  616. let row = NSStackView()
  617. row.orientation = .horizontal
  618. row.spacing = 8
  619. row.translatesAutoresizingMaskIntoConstraints = false
  620. let lab = label("PORTFOLIO SNAPSHOT", font: .systemFont(ofSize: 12, weight: .heavy), color: style.ink, maxLines: 1)
  621. row.addArrangedSubview(stripe)
  622. row.addArrangedSubview(lab)
  623. v.addSubview(row)
  624. NSLayoutConstraint.activate([
  625. stripe.widthAnchor.constraint(equalToConstant: 4),
  626. stripe.heightAnchor.constraint(equalToConstant: 18),
  627. row.leadingAnchor.constraint(equalTo: v.leadingAnchor),
  628. row.topAnchor.constraint(equalTo: v.topAnchor),
  629. row.bottomAnchor.constraint(equalTo: v.bottomAnchor)
  630. ])
  631. return v
  632. }
  633. private func creativeMainStack(theme: NSColor) -> NSView {
  634. let stack = NSStackView()
  635. stack.orientation = .vertical
  636. stack.spacing = style.bodyBlockSpacing
  637. stack.alignment = .leading
  638. stack.addArrangedSubview(creativeMainHeader(theme: theme))
  639. if let summary = nonEmpty(profile.careerSummary) {
  640. stack.addArrangedSubview(sectionHeading("Profile"))
  641. stack.addArrangedSubview(paragraph(summary, compact: false))
  642. }
  643. let jobs = profile.workExperiences.filter { !$0.isEffectivelyEmpty }
  644. if !jobs.isEmpty {
  645. stack.addArrangedSubview(sectionHeading("Impact"))
  646. for job in jobs {
  647. let titleLine = [job.jobTitle, job.company].filter { !$0.isEmpty }.joined(separator: " — ")
  648. if !titleLine.isEmpty {
  649. stack.addArrangedSubview(label(titleLine, font: .systemFont(ofSize: 13.5, weight: .heavy), color: style.ink, maxLines: 0))
  650. }
  651. for bullet in Self.bulletChunks(from: job.description) {
  652. let mark = (variant % 2 == 0) ? "— " : "▸ "
  653. stack.addArrangedSubview(label("\(mark)\(bullet)", font: style.bodyFont, color: style.muted, maxLines: 0))
  654. }
  655. }
  656. }
  657. let schools = profile.educations.filter { !$0.isEffectivelyEmpty }
  658. if !schools.isEmpty {
  659. stack.addArrangedSubview(sectionHeading("Education"))
  660. for edu in schools {
  661. stack.addArrangedSubview(educationBlock(edu: edu, compact: false))
  662. }
  663. }
  664. appendCertificatesInterestsReferrals(to: stack, compact: false)
  665. return stack
  666. }
  667. // MARK: - Traditional families (professional / minimal / executive)
  668. private func buildTraditionalFamilyDocument() -> NSView {
  669. switch template.layout {
  670. case .singleColumn:
  671. return singleColumnLayout()
  672. case .twoColumn(let side, let tinted):
  673. return twoColumnLayout(sidebar: side, tinted: tinted)
  674. }
  675. }
  676. private func singleColumnLayout() -> NSView {
  677. let v = NSStackView()
  678. v.orientation = .vertical
  679. v.alignment = .leading
  680. v.spacing = style.columnVerticalSpacing + 3
  681. v.addArrangedSubview(headerBlock())
  682. if template.family == .professional && (variant % 6) == 4 {
  683. v.addArrangedSubview(professionalInlineSkillsRow())
  684. }
  685. v.addArrangedSubview(hairline())
  686. let body = bodyColumn(compact: false, experienceFirst: professionalExperienceFirst)
  687. v.addArrangedSubview(usesProfessionalSingleColumnRail ? bodyWithLeadingAccentRail(body) : body)
  688. return v
  689. }
  690. private var professionalExperienceFirst: Bool {
  691. template.family == .professional && (variant % 3) == 1
  692. }
  693. private func professionalInlineSkillsRow() -> NSView {
  694. let tokens = skillTokensFromProfile(max: 6)
  695. guard !tokens.isEmpty else { return NSView() }
  696. let joined = tokens.joined(separator: " · ")
  697. return label(joined, font: .systemFont(ofSize: 11.5, weight: .medium), color: template.themeColor, maxLines: 0)
  698. }
  699. /// Matches the CV Maker thumbnail: professional ATS single-column layouts use a full-height theme rail.
  700. private var usesProfessionalSingleColumnRail: Bool {
  701. if case .singleColumn = template.layout, template.family == .professional { return true }
  702. return false
  703. }
  704. private func bodyWithLeadingAccentRail(_ content: NSView) -> NSView {
  705. let wrap = NSView()
  706. wrap.translatesAutoresizingMaskIntoConstraints = false
  707. let rail = NSView()
  708. rail.translatesAutoresizingMaskIntoConstraints = false
  709. rail.wantsLayer = true
  710. rail.layer?.backgroundColor = template.themeColor.cgColor
  711. rail.layer?.cornerRadius = 1
  712. content.translatesAutoresizingMaskIntoConstraints = false
  713. wrap.addSubview(rail)
  714. wrap.addSubview(content)
  715. NSLayoutConstraint.activate([
  716. rail.leadingAnchor.constraint(equalTo: wrap.leadingAnchor),
  717. rail.topAnchor.constraint(equalTo: content.topAnchor),
  718. rail.bottomAnchor.constraint(equalTo: content.bottomAnchor),
  719. rail.widthAnchor.constraint(equalToConstant: 3),
  720. content.leadingAnchor.constraint(equalTo: rail.trailingAnchor, constant: 12),
  721. content.trailingAnchor.constraint(equalTo: wrap.trailingAnchor),
  722. content.topAnchor.constraint(equalTo: wrap.topAnchor),
  723. content.bottomAnchor.constraint(equalTo: wrap.bottomAnchor)
  724. ])
  725. return wrap
  726. }
  727. private func twoColumnLayout(sidebar: CVTemplate.SidebarSide, tinted: Bool) -> NSView {
  728. let v = NSStackView()
  729. v.orientation = .vertical
  730. v.alignment = .leading
  731. v.spacing = style.columnVerticalSpacing + 2
  732. v.addArrangedSubview(headerBlock())
  733. v.addArrangedSubview(hairline())
  734. let row = NSStackView()
  735. row.orientation = .horizontal
  736. row.alignment = .top
  737. row.spacing = template.family == .minimal ? 18 : 22
  738. let sidebarCol = sidebarColumn(tinted: tinted)
  739. let mainCol = bodyColumn(compact: true, experienceFirst: professionalExperienceFirst)
  740. if sidebar == .leading {
  741. row.addArrangedSubview(sidebarCol)
  742. row.addArrangedSubview(mainCol)
  743. } else {
  744. row.addArrangedSubview(mainCol)
  745. row.addArrangedSubview(sidebarCol)
  746. }
  747. let sidebarMult: CGFloat
  748. if template.family == .professional {
  749. sidebarMult = (variant % 5 == 2) ? 0.38 : 0.32
  750. } else {
  751. sidebarMult = template.family == .executive ? 0.34 : 0.32
  752. }
  753. sidebarCol.widthAnchor.constraint(equalTo: row.widthAnchor, multiplier: sidebarMult).isActive = true
  754. v.addArrangedSubview(row)
  755. return v
  756. }
  757. private func headerBlock() -> NSView {
  758. let nameText = displayable(profile.personal.fullName, placeholder: "Your name")
  759. let roleText = displayable(profile.personal.jobTitle, placeholder: "Professional headline")
  760. let contactParts = [profile.personal.email, profile.personal.phone, profile.personal.address].filter { !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }
  761. let contactText = contactParts.isEmpty ? "Add contact details in your profile" : contactParts.joined(separator: " · ")
  762. let roleColor = style.roleUsesThemeColor ? template.themeColor : style.muted
  763. let name = label(nameText, font: style.nameFont, color: style.ink, maxLines: 2)
  764. let role = label(roleText, font: style.roleFont, color: roleColor, maxLines: 2)
  765. let contact = label(contactText, font: style.contactFont, color: style.muted.withAlphaComponent(0.92), maxLines: 3)
  766. let textCol = NSStackView(views: [name, role, contact])
  767. textCol.orientation = .vertical
  768. textCol.spacing = template.family == .professional ? 3 : 4
  769. textCol.alignment = .leading
  770. switch template.headline {
  771. case .centered:
  772. textCol.alignment = .centerX
  773. name.alignment = .center
  774. role.alignment = .center
  775. contact.alignment = .center
  776. let accent = headlineAccent()
  777. let stack = NSStackView(views: [textCol, accent])
  778. stack.orientation = .vertical
  779. stack.spacing = 8
  780. stack.alignment = .centerX
  781. return stack
  782. case .avatarStacked:
  783. textCol.alignment = .centerX
  784. name.alignment = .center
  785. role.alignment = .center
  786. contact.alignment = .center
  787. let accent = headlineAccent()
  788. let avatar = initialsBadge(for: nameText)
  789. let stack = NSStackView(views: [avatar, textCol, accent])
  790. stack.orientation = .vertical
  791. stack.spacing = 8
  792. stack.alignment = .centerX
  793. return stack
  794. case .leftAligned, .leftWithInitials:
  795. let row = NSStackView()
  796. row.orientation = .horizontal
  797. row.spacing = 14
  798. row.alignment = .centerY
  799. row.addArrangedSubview(textCol)
  800. if template.headline == .leftWithInitials {
  801. row.addArrangedSubview(NSView())
  802. row.addArrangedSubview(initialsBadge(for: nameText))
  803. }
  804. let col = NSStackView(views: [row, headlineAccent()])
  805. col.orientation = .vertical
  806. col.spacing = 8
  807. col.alignment = .leading
  808. return col
  809. }
  810. }
  811. private func initialsBadge(for fullName: String) -> NSView {
  812. let initials = Self.initials(from: fullName)
  813. let t = NSTextField(labelWithString: initials)
  814. t.font = .systemFont(ofSize: 13, weight: .bold)
  815. t.textColor = template.themeColor
  816. t.alignment = .center
  817. t.translatesAutoresizingMaskIntoConstraints = false
  818. let wrap = NSView()
  819. wrap.translatesAutoresizingMaskIntoConstraints = false
  820. wrap.wantsLayer = true
  821. wrap.layer?.cornerRadius = 22
  822. wrap.layer?.borderWidth = 1.5
  823. wrap.layer?.borderColor = template.themeColor.withAlphaComponent(0.35).cgColor
  824. wrap.addSubview(t)
  825. NSLayoutConstraint.activate([
  826. wrap.widthAnchor.constraint(equalToConstant: 44),
  827. wrap.heightAnchor.constraint(equalToConstant: 44),
  828. t.centerXAnchor.constraint(equalTo: wrap.centerXAnchor),
  829. t.centerYAnchor.constraint(equalTo: wrap.centerYAnchor)
  830. ])
  831. return wrap
  832. }
  833. private static func initials(from fullName: String) -> String {
  834. let parts = fullName.split(separator: " ").filter { !$0.isEmpty }
  835. if parts.count >= 2 {
  836. let a = parts[0].prefix(1)
  837. let b = parts[1].prefix(1)
  838. return "\(a)\(b)".uppercased()
  839. }
  840. if let first = parts.first { return String(first.prefix(2)).uppercased() }
  841. return "CV"
  842. }
  843. private func headlineAccent() -> NSView {
  844. let bar = NSView()
  845. bar.translatesAutoresizingMaskIntoConstraints = false
  846. bar.wantsLayer = true
  847. switch template.accent {
  848. case .none:
  849. bar.heightAnchor.constraint(equalToConstant: 1).isActive = true
  850. return bar
  851. case .redUnderline:
  852. bar.layer?.backgroundColor = NSColor(srgbRed: 207 / 255, green: 67 / 255, blue: 50 / 255, alpha: 1).cgColor
  853. bar.heightAnchor.constraint(equalToConstant: 2).isActive = true
  854. bar.widthAnchor.constraint(equalToConstant: template.family == .minimal ? 140 : 168).isActive = true
  855. return bar
  856. case .redBar:
  857. bar.layer?.backgroundColor = NSColor(srgbRed: 207 / 255, green: 67 / 255, blue: 50 / 255, alpha: 1).cgColor
  858. bar.heightAnchor.constraint(equalToConstant: 4).isActive = true
  859. bar.widthAnchor.constraint(equalToConstant: 56).isActive = true
  860. return bar
  861. case .blueBar:
  862. bar.layer?.backgroundColor = template.themeColor.cgColor
  863. if template.headline == .centered {
  864. bar.heightAnchor.constraint(equalToConstant: 2.5).isActive = true
  865. bar.widthAnchor.constraint(equalToConstant: 148).isActive = true
  866. } else {
  867. bar.heightAnchor.constraint(equalToConstant: 4).isActive = true
  868. bar.widthAnchor.constraint(equalToConstant: template.family == .executive ? 100 : 120).isActive = true
  869. }
  870. return bar
  871. }
  872. }
  873. private func hairline() -> NSView {
  874. let v = NSView()
  875. v.translatesAutoresizingMaskIntoConstraints = false
  876. v.wantsLayer = true
  877. v.layer?.backgroundColor = style.rule.cgColor
  878. let h: CGFloat = template.family == .executive ? 1.5 : 1
  879. v.heightAnchor.constraint(equalToConstant: h).isActive = true
  880. return v
  881. }
  882. private func sidebarColumn(tinted: Bool) -> NSView {
  883. let box = NSStackView()
  884. box.orientation = .vertical
  885. box.spacing = 12
  886. box.alignment = .leading
  887. if tinted {
  888. box.wantsLayer = true
  889. box.layer?.backgroundColor = template.themeColor.withAlphaComponent(template.family == .creative ? 0.12 : 0.08).cgColor
  890. box.layer?.cornerRadius = 8
  891. }
  892. box.edgeInsets = NSEdgeInsets(top: tinted ? 14 : 0, left: tinted ? 14 : 0, bottom: tinted ? 14 : 0, right: tinted ? 14 : 0)
  893. box.addArrangedSubview(sectionHeading("Contact"))
  894. for line in contactLines() {
  895. box.addArrangedSubview(label(line, font: style.contactFont, color: style.ink, maxLines: 0))
  896. }
  897. if let skillsBlock = ancillaryBlock(title: "Languages & more", body: combinedAncillaryText()) {
  898. box.addArrangedSubview(skillsBlock)
  899. }
  900. return box
  901. }
  902. private func bodyColumn(compact: Bool, experienceFirst: Bool = false) -> NSView {
  903. let v = NSStackView()
  904. v.orientation = .vertical
  905. v.spacing = compact ? style.bodyBlockSpacing : style.bodyBlockSpacing + 2
  906. v.alignment = .leading
  907. let summaryTitle = sectionHeading(summarySectionTitle)
  908. let summaryBody: NSView? = nonEmpty(profile.careerSummary).map { paragraph($0, compact: compact) }
  909. let jobs = profile.workExperiences.filter { !$0.isEffectivelyEmpty }
  910. let experienceHeading = sectionHeading("Experience")
  911. var experienceBlocks: [NSView] = []
  912. for job in jobs {
  913. experienceBlocks.append(experienceBlock(job: job, compact: compact))
  914. }
  915. let schools = profile.educations.filter { !$0.isEffectivelyEmpty }
  916. var educationBlocks: [NSView] = []
  917. for edu in schools {
  918. educationBlocks.append(educationBlock(edu: edu, compact: compact))
  919. }
  920. let appendSummary: () -> Void = { [self] in
  921. if let body = summaryBody {
  922. v.addArrangedSubview(summaryTitle)
  923. v.addArrangedSubview(body)
  924. }
  925. }
  926. let appendExperience: () -> Void = { [self] in
  927. if !jobs.isEmpty {
  928. v.addArrangedSubview(experienceHeading)
  929. experienceBlocks.forEach { v.addArrangedSubview($0) }
  930. }
  931. }
  932. let appendEducation: () -> Void = { [self] in
  933. if !schools.isEmpty {
  934. v.addArrangedSubview(sectionHeading("Education"))
  935. educationBlocks.forEach { v.addArrangedSubview($0) }
  936. }
  937. }
  938. if experienceFirst {
  939. appendExperience()
  940. appendSummary()
  941. appendEducation()
  942. } else {
  943. appendSummary()
  944. appendExperience()
  945. appendEducation()
  946. }
  947. appendCertificatesInterestsReferrals(to: v, compact: compact)
  948. return v
  949. }
  950. private func appendCertificatesInterestsReferrals(to v: NSStackView, compact: Bool) {
  951. if let cert = nonEmpty(profile.certificates) {
  952. v.addArrangedSubview(sectionHeading("Certificates"))
  953. v.addArrangedSubview(paragraph(cert, compact: compact))
  954. }
  955. if let interests = nonEmpty(profile.interests) {
  956. v.addArrangedSubview(sectionHeading("Interests"))
  957. v.addArrangedSubview(paragraph(interests, compact: compact))
  958. }
  959. if let ref = nonEmpty(profile.referral) {
  960. v.addArrangedSubview(sectionHeading("Referrals"))
  961. v.addArrangedSubview(paragraph(ref, compact: compact))
  962. }
  963. }
  964. private func skillTokensFromProfile(max: Int) -> [String] {
  965. let raw = profile.languages.trimmingCharacters(in: .whitespacesAndNewlines)
  966. if raw.isEmpty { return [] }
  967. let parts = raw.split(whereSeparator: { $0 == "," || $0 == "·" || $0 == "|" || $0 == ";" })
  968. .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
  969. .filter { !$0.isEmpty }
  970. if parts.count > 1 { return Array(parts.prefix(max)) }
  971. return raw.split(separator: " ").map(String.init).filter { $0.count > 1 }.prefix(max).map { String($0) }
  972. }
  973. private func highlightsBodyText() -> String? {
  974. if let t = nonEmpty(profile.interests) { return t }
  975. if let r = nonEmpty(profile.referral) { return r }
  976. let jobs = profile.workExperiences.filter { !$0.isEffectivelyEmpty }
  977. if let first = jobs.first {
  978. let bullets = Self.bulletChunks(from: first.description)
  979. if let b = bullets.first { return b }
  980. }
  981. return nil
  982. }
  983. private func ancillaryBlock(title: String, body: String?) -> NSStackView? {
  984. guard let body, !body.isEmpty else { return nil }
  985. let s = NSStackView()
  986. s.orientation = .vertical
  987. s.spacing = 6
  988. s.alignment = .leading
  989. s.addArrangedSubview(sectionHeading(title))
  990. s.addArrangedSubview(paragraph(body, compact: true))
  991. return s
  992. }
  993. private func contactLines() -> [String] {
  994. var lines: [String] = []
  995. let p = profile.personal
  996. if !p.email.isEmpty { lines.append(p.email) }
  997. if !p.phone.isEmpty { lines.append(p.phone) }
  998. if !p.address.isEmpty { lines.append(p.address) }
  999. return lines.isEmpty ? ["—"] : lines
  1000. }
  1001. private func combinedAncillaryText() -> String? {
  1002. let chunks = [profile.languages, profile.interests].map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }.filter { !$0.isEmpty }
  1003. return chunks.isEmpty ? nil : chunks.joined(separator: "\n\n")
  1004. }
  1005. private func experienceBlock(job: WorkExperiencePayload, compact: Bool) -> NSView {
  1006. let v = NSStackView()
  1007. v.orientation = .vertical
  1008. v.spacing = template.family == .professional ? 4 : 6
  1009. v.alignment = .leading
  1010. if template.family == .professional {
  1011. let title = job.jobTitle.trimmingCharacters(in: .whitespacesAndNewlines)
  1012. let company = job.company.trimmingCharacters(in: .whitespacesAndNewlines)
  1013. let duration = job.duration.trimmingCharacters(in: .whitespacesAndNewlines)
  1014. if !title.isEmpty {
  1015. v.addArrangedSubview(label(title, font: style.expTitleFont, color: style.ink, maxLines: 0))
  1016. }
  1017. let metaParts = [company, duration].filter { !$0.isEmpty }
  1018. if !metaParts.isEmpty {
  1019. let metaJoined = metaParts.joined(separator: " · ")
  1020. v.addArrangedSubview(label(metaJoined, font: style.expMetaFont, color: template.themeColor, maxLines: 0))
  1021. } else if title.isEmpty {
  1022. let fallback = [job.jobTitle, job.company].filter { !$0.isEmpty }.joined(separator: " — ")
  1023. if !fallback.isEmpty {
  1024. v.addArrangedSubview(label(fallback, font: style.expTitleFont, color: style.ink, maxLines: 0))
  1025. }
  1026. }
  1027. } else {
  1028. let titleLine = [job.jobTitle, job.company].filter { !$0.isEmpty }.joined(separator: " — ")
  1029. let meta = job.duration.trimmingCharacters(in: .whitespacesAndNewlines)
  1030. if !titleLine.isEmpty {
  1031. v.addArrangedSubview(label(titleLine, font: style.expTitleFont, color: style.ink, maxLines: 0))
  1032. }
  1033. if !meta.isEmpty {
  1034. v.addArrangedSubview(label(meta, font: style.expMetaFont, color: template.themeColor, maxLines: 0))
  1035. }
  1036. }
  1037. for bullet in Self.bulletChunks(from: job.description) {
  1038. v.addArrangedSubview(bulletRow(bullet, compact: compact))
  1039. }
  1040. return v
  1041. }
  1042. private func educationBlock(edu: EducationPayload, compact: Bool) -> NSView {
  1043. let v = NSStackView()
  1044. v.orientation = .vertical
  1045. v.spacing = 4
  1046. v.alignment = .leading
  1047. let institution = edu.institution.trimmingCharacters(in: .whitespacesAndNewlines)
  1048. let degree = edu.degree.trimmingCharacters(in: .whitespacesAndNewlines)
  1049. let year = edu.year.trimmingCharacters(in: .whitespacesAndNewlines)
  1050. if template.family == .professional {
  1051. if !institution.isEmpty {
  1052. v.addArrangedSubview(label(institution, font: style.eduTitleFont, color: style.ink, maxLines: 0))
  1053. }
  1054. let subParts = [degree, year].filter { !$0.isEmpty }
  1055. if !subParts.isEmpty {
  1056. let sub = subParts.joined(separator: " · ")
  1057. v.addArrangedSubview(label(sub, font: style.eduMetaFont, color: style.muted, maxLines: 0))
  1058. }
  1059. } else {
  1060. let head = [edu.institution, edu.degree].filter { !$0.isEmpty }.joined(separator: " — ")
  1061. if !head.isEmpty {
  1062. v.addArrangedSubview(label(head, font: style.eduTitleFont, color: style.ink, maxLines: 0))
  1063. }
  1064. if !edu.year.isEmpty {
  1065. v.addArrangedSubview(label(edu.year, font: style.eduMetaFont, color: style.muted, maxLines: 0))
  1066. }
  1067. }
  1068. return v
  1069. }
  1070. private func bulletRow(_ text: String, compact: Bool) -> NSView {
  1071. let marker: String = template.family == .minimal ? "·" : "•"
  1072. let dot = NSTextField(labelWithString: marker)
  1073. dot.font = style.bulletMarkerFont
  1074. dot.textColor = style.bulletMarkerColor
  1075. dot.translatesAutoresizingMaskIntoConstraints = false
  1076. let bodyFont = compact ? style.bodyCompactFont : style.bulletBodyFont
  1077. let body = label(text, font: bodyFont, color: style.ink, maxLines: 0)
  1078. let row = NSStackView(views: [dot, body])
  1079. row.orientation = .horizontal
  1080. row.spacing = template.family == .creative ? 10 : 8
  1081. row.alignment = .top
  1082. dot.setContentHuggingPriority(.required, for: .horizontal)
  1083. return row
  1084. }
  1085. private func paragraph(_ text: String, compact: Bool) -> NSTextField {
  1086. let font = compact ? style.bodyCompactFont : style.bodyFont
  1087. return label(text, font: font, color: style.ink, maxLines: 0)
  1088. }
  1089. /// Gallery + ATS “Clear Path” style use “Profile”; other families keep the neutral résumé label.
  1090. private var summarySectionTitle: String {
  1091. template.family == .professional ? "Profile" : "Summary"
  1092. }
  1093. private func sectionHeading(_ raw: String) -> NSTextField {
  1094. let upper = raw.uppercased()
  1095. let s: String
  1096. switch template.sectionLabelStyle {
  1097. case .uppercase: s = upper
  1098. case .slashed: s = "// \(upper)"
  1099. case .bracketed: s = "[ \(upper) ]"
  1100. }
  1101. let t = NSTextField(labelWithString: s)
  1102. t.font = style.sectionFont
  1103. t.textColor = style.sectionInk
  1104. t.alignment = .left
  1105. return t
  1106. }
  1107. private func label(_ string: String, font: NSFont, color: NSColor, maxLines: Int) -> NSTextField {
  1108. let isWrapping = maxLines == 0
  1109. let t: NSTextField
  1110. if isWrapping {
  1111. t = NSTextField(wrappingLabelWithString: string)
  1112. t.maximumNumberOfLines = 0
  1113. } else {
  1114. t = NSTextField(labelWithString: string)
  1115. t.maximumNumberOfLines = maxLines
  1116. }
  1117. t.font = font
  1118. t.textColor = color
  1119. t.alignment = .left
  1120. if isEditable {
  1121. t.isEditable = true
  1122. t.isSelectable = true
  1123. t.isBordered = false
  1124. t.drawsBackground = false
  1125. t.focusRingType = .default
  1126. }
  1127. return t
  1128. }
  1129. private func displayable(_ value: String, placeholder: String) -> String {
  1130. let t = value.trimmingCharacters(in: .whitespacesAndNewlines)
  1131. return t.isEmpty ? placeholder : t
  1132. }
  1133. private func nonEmpty(_ value: String) -> String? {
  1134. let t = value.trimmingCharacters(in: .whitespacesAndNewlines)
  1135. return t.isEmpty ? nil : t
  1136. }
  1137. private static func bulletChunks(from text: String) -> [String] {
  1138. let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
  1139. if trimmed.isEmpty { return [] }
  1140. let byNewline = trimmed.components(separatedBy: .newlines)
  1141. .map { $0.trimmingCharacters(in: .whitespaces) }
  1142. .filter { !$0.isEmpty }
  1143. if byNewline.count > 1 { return byNewline }
  1144. let byBullet = trimmed.split(separator: "•")
  1145. .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
  1146. .filter { !$0.isEmpty }
  1147. if byBullet.count > 1 { return byBullet.map { String($0) } }
  1148. return [trimmed]
  1149. }
  1150. }
  1151. // MARK: - Payload helpers
  1152. private extension WorkExperiencePayload {
  1153. var isEffectivelyEmpty: Bool {
  1154. [jobTitle, company, duration, description].allSatisfy { $0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }
  1155. }
  1156. }
  1157. private extension EducationPayload {
  1158. var isEffectivelyEmpty: Bool {
  1159. [degree, institution, year].allSatisfy { $0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }
  1160. }
  1161. }