暂无描述

CVProfileDocumentView.swift 72KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652
  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. let colors = CVResumeAppearance.colors()
  39. let sectionInk = CVResumeAppearance.sectionHeadingColor(for: template)
  40. let cardBG = CVResumeAppearance.paperBackground(
  41. variant: template.galleryLayoutVariant,
  42. base: colors.cardBackground
  43. )
  44. switch template.family {
  45. case .minimal:
  46. return DocumentStyle(
  47. nameFont: .systemFont(ofSize: 20, weight: .regular),
  48. roleFont: .systemFont(ofSize: 13.5, weight: .regular),
  49. contactFont: .systemFont(ofSize: 11.5, weight: .regular),
  50. sectionFont: .systemFont(ofSize: 10.5, weight: .semibold),
  51. bodyFont: .systemFont(ofSize: 12.5, weight: .regular),
  52. bodyCompactFont: .systemFont(ofSize: 12, weight: .regular),
  53. expTitleFont: .systemFont(ofSize: 13, weight: .medium),
  54. expMetaFont: .systemFont(ofSize: 11.5, weight: .regular),
  55. eduTitleFont: .systemFont(ofSize: 13, weight: .medium),
  56. eduMetaFont: .systemFont(ofSize: 11.5, weight: .regular),
  57. bulletBodyFont: .systemFont(ofSize: 12, weight: .regular),
  58. bulletMarkerFont: .systemFont(ofSize: 11, weight: .light),
  59. bulletMarkerColor: theme.withAlphaComponent(0.55),
  60. ink: colors.ink,
  61. muted: colors.muted,
  62. rule: colors.rule,
  63. cardBackground: cardBG,
  64. columnVerticalSpacing: 15,
  65. bodyBlockSpacing: 15,
  66. roleUsesThemeColor: false,
  67. sectionInk: sectionInk
  68. )
  69. case .professional:
  70. return DocumentStyle(
  71. nameFont: .systemFont(ofSize: 21, weight: .semibold),
  72. roleFont: .systemFont(ofSize: 13.5, weight: .medium),
  73. contactFont: .systemFont(ofSize: 11.5, weight: .regular),
  74. sectionFont: .systemFont(ofSize: 10.5, weight: .heavy),
  75. bodyFont: .systemFont(ofSize: 12, weight: .regular),
  76. bodyCompactFont: .systemFont(ofSize: 11.5, weight: .regular),
  77. expTitleFont: .systemFont(ofSize: 13.5, weight: .semibold),
  78. expMetaFont: .systemFont(ofSize: 11.5, weight: .semibold),
  79. eduTitleFont: .systemFont(ofSize: 13, weight: .semibold),
  80. eduMetaFont: .systemFont(ofSize: 11.5, weight: .medium),
  81. bulletBodyFont: .systemFont(ofSize: 12, weight: .regular),
  82. bulletMarkerFont: .systemFont(ofSize: 12, weight: .bold),
  83. bulletMarkerColor: theme,
  84. ink: colors.ink,
  85. muted: colors.muted,
  86. rule: colors.rule,
  87. cardBackground: cardBG,
  88. columnVerticalSpacing: 13,
  89. bodyBlockSpacing: 13,
  90. roleUsesThemeColor: false,
  91. sectionInk: sectionInk
  92. )
  93. case .modern:
  94. return DocumentStyle(
  95. nameFont: .systemFont(ofSize: 22, weight: .bold),
  96. roleFont: .systemFont(ofSize: 14, weight: .semibold),
  97. contactFont: .systemFont(ofSize: 12, weight: .regular),
  98. sectionFont: .systemFont(ofSize: 11, weight: .heavy),
  99. bodyFont: .systemFont(ofSize: 12.5, weight: .regular),
  100. bodyCompactFont: .systemFont(ofSize: 12, weight: .regular),
  101. expTitleFont: .systemFont(ofSize: 14, weight: .bold),
  102. expMetaFont: .systemFont(ofSize: 12, weight: .medium),
  103. eduTitleFont: .systemFont(ofSize: 13.5, weight: .bold),
  104. eduMetaFont: .systemFont(ofSize: 12, weight: .regular),
  105. bulletBodyFont: .systemFont(ofSize: 12.5, weight: .regular),
  106. bulletMarkerFont: .systemFont(ofSize: 13, weight: .bold),
  107. bulletMarkerColor: theme,
  108. ink: colors.ink,
  109. muted: colors.muted,
  110. rule: colors.rule,
  111. cardBackground: cardBG,
  112. columnVerticalSpacing: 17,
  113. bodyBlockSpacing: 16,
  114. roleUsesThemeColor: true,
  115. sectionInk: sectionInk
  116. )
  117. case .executive:
  118. let serifName = NSFont(name: "Georgia-Bold", size: 23) ?? .systemFont(ofSize: 23, weight: .semibold)
  119. let serifRole = NSFont(name: "Georgia", size: 14) ?? .systemFont(ofSize: 14, weight: .regular)
  120. let serifBody = NSFont(name: "Georgia", size: 12.5) ?? .systemFont(ofSize: 12.5, weight: .regular)
  121. let serifCompact = NSFont(name: "Georgia", size: 12) ?? .systemFont(ofSize: 12, weight: .regular)
  122. let georgia12 = NSFont(name: "Georgia", size: 12) ?? .systemFont(ofSize: 12)
  123. let georgia115 = NSFont(name: "Georgia", size: 11.5) ?? .systemFont(ofSize: 11.5)
  124. let expMeta = NSFont(name: "Georgia-Italic", size: 12)
  125. ?? NSFontManager.shared.convert(georgia12, toHaveTrait: .italicFontMask)
  126. let eduMeta = NSFont(name: "Georgia-Italic", size: 11.5)
  127. ?? NSFontManager.shared.convert(georgia115, toHaveTrait: .italicFontMask)
  128. let execCard = CVResumeAppearance.isDark
  129. ? cardBG
  130. : NSColor(srgbRed: 0.992, green: 0.99, blue: 0.985, alpha: 1)
  131. return DocumentStyle(
  132. nameFont: serifName,
  133. roleFont: serifRole,
  134. contactFont: NSFont(name: "Georgia", size: 11.5) ?? .systemFont(ofSize: 11.5),
  135. sectionFont: .systemFont(ofSize: 10.5, weight: .heavy),
  136. bodyFont: serifBody,
  137. bodyCompactFont: serifCompact,
  138. expTitleFont: NSFont(name: "Georgia-Bold", size: 14) ?? .systemFont(ofSize: 14, weight: .semibold),
  139. expMetaFont: expMeta,
  140. eduTitleFont: NSFont(name: "Georgia-Bold", size: 13.5) ?? .systemFont(ofSize: 13.5, weight: .semibold),
  141. eduMetaFont: eduMeta,
  142. bulletBodyFont: serifCompact,
  143. bulletMarkerFont: .systemFont(ofSize: 11, weight: .bold),
  144. bulletMarkerColor: colors.ink.withAlphaComponent(0.75),
  145. ink: colors.ink,
  146. muted: colors.muted,
  147. rule: colors.rule,
  148. cardBackground: execCard,
  149. columnVerticalSpacing: 18,
  150. bodyBlockSpacing: 17,
  151. roleUsesThemeColor: false,
  152. sectionInk: sectionInk
  153. )
  154. case .creative:
  155. return DocumentStyle(
  156. nameFont: .systemFont(ofSize: 23, weight: .heavy),
  157. roleFont: .systemFont(ofSize: 14, weight: .semibold),
  158. contactFont: .systemFont(ofSize: 11.5, weight: .medium),
  159. sectionFont: .systemFont(ofSize: 11.5, weight: .heavy),
  160. bodyFont: .systemFont(ofSize: 12.5, weight: .regular),
  161. bodyCompactFont: .systemFont(ofSize: 12, weight: .regular),
  162. expTitleFont: .systemFont(ofSize: 14, weight: .heavy),
  163. expMetaFont: .systemFont(ofSize: 12, weight: .semibold),
  164. eduTitleFont: .systemFont(ofSize: 13.5, weight: .heavy),
  165. eduMetaFont: .systemFont(ofSize: 12, weight: .medium),
  166. bulletBodyFont: .systemFont(ofSize: 12.5, weight: .regular),
  167. bulletMarkerFont: .systemFont(ofSize: 13, weight: .heavy),
  168. bulletMarkerColor: CVResumeAppearance.accentColor(for: template),
  169. ink: colors.ink,
  170. muted: colors.muted,
  171. rule: theme.withAlphaComponent(0.22),
  172. cardBackground: cardBG,
  173. columnVerticalSpacing: 18,
  174. bodyBlockSpacing: 17,
  175. roleUsesThemeColor: true,
  176. sectionInk: sectionInk
  177. )
  178. }
  179. }
  180. }
  181. /// Full-width résumé layout that injects `SavedProfile` into the visual language of `CVTemplate`.
  182. final class CVProfileDocumentView: NSView {
  183. /// Card width used in the CV preview; also the horizontal fitting size for this view.
  184. /// Without this, a parent `NSStackView` that only pins `width ≤ …` can size the document from
  185. /// wrapping `NSTextField` intrinsic widths (~0) and the whole page collapses to a thin strip.
  186. private static let cardWidth: CGFloat = 640
  187. private let profile: SavedProfile
  188. private let template: CVTemplate
  189. private var style: DocumentStyle
  190. /// Matches `CVTemplatePreviewView` so the same template id + layout recipe renders the same silhouette as the gallery card.
  191. private let variant: Int
  192. private var appearanceObserver: NSObjectProtocol?
  193. private weak var cardView: NSView?
  194. init(profile: SavedProfile, template: CVTemplate) {
  195. self.profile = profile
  196. self.template = template
  197. self.style = DocumentStyle.make(for: template)
  198. self.variant = template.galleryLayoutVariant
  199. super.init(frame: .zero)
  200. translatesAutoresizingMaskIntoConstraints = false
  201. wantsLayer = true
  202. layer?.backgroundColor = NSColor.clear.cgColor
  203. userInterfaceLayoutDirection = .leftToRight
  204. setContentHuggingPriority(.defaultLow, for: .horizontal)
  205. installCardContent()
  206. appearanceObserver = NotificationCenter.default.addObserver(
  207. forName: AppAppearanceManager.didChangeNotification,
  208. object: nil,
  209. queue: .main
  210. ) { [weak self] _ in
  211. self?.refreshForAppearanceChange()
  212. }
  213. }
  214. deinit {
  215. if let appearanceObserver {
  216. NotificationCenter.default.removeObserver(appearanceObserver)
  217. }
  218. }
  219. override func viewDidChangeEffectiveAppearance() {
  220. super.viewDidChangeEffectiveAppearance()
  221. refreshForAppearanceChange()
  222. }
  223. private func refreshForAppearanceChange() {
  224. style = DocumentStyle.make(for: template)
  225. installCardContent()
  226. }
  227. private func installCardContent() {
  228. subviews.forEach { $0.removeFromSuperview() }
  229. let card = NSView()
  230. card.translatesAutoresizingMaskIntoConstraints = false
  231. card.wantsLayer = true
  232. card.layer?.backgroundColor = style.cardBackground.cgColor
  233. card.layer?.cornerRadius = template.family == .executive ? 6 : 10
  234. card.layer?.borderWidth = 1
  235. card.layer?.borderColor = style.rule.cgColor
  236. card.layer?.masksToBounds = true
  237. cardView = card
  238. let root = buildRoot()
  239. root.translatesAutoresizingMaskIntoConstraints = false
  240. card.addSubview(root)
  241. addSubview(card)
  242. NSLayoutConstraint.activate([
  243. card.leadingAnchor.constraint(equalTo: leadingAnchor),
  244. card.trailingAnchor.constraint(equalTo: trailingAnchor),
  245. card.topAnchor.constraint(equalTo: topAnchor),
  246. card.bottomAnchor.constraint(equalTo: bottomAnchor),
  247. card.widthAnchor.constraint(equalToConstant: Self.cardWidth),
  248. root.leadingAnchor.constraint(equalTo: card.leadingAnchor, constant: 36),
  249. root.trailingAnchor.constraint(equalTo: card.trailingAnchor, constant: -36),
  250. root.topAnchor.constraint(equalTo: card.topAnchor, constant: 32),
  251. root.bottomAnchor.constraint(equalTo: card.bottomAnchor, constant: -36)
  252. ])
  253. }
  254. @available(*, unavailable)
  255. required init?(coder: NSCoder) {
  256. fatalError("init(coder:) has not been implemented")
  257. }
  258. override var intrinsicContentSize: NSSize {
  259. NSSize(width: Self.cardWidth, height: NSView.noIntrinsicMetric)
  260. }
  261. override func layout() {
  262. super.layout()
  263. // Wrapping `NSTextField`s default to a very small intrinsic width until
  264. // `preferredMaxLayoutWidth` tracks the column width — stacks then collapse and text reflows like a narrow strip.
  265. updateWrappingTextPreferredWidths()
  266. }
  267. /// Any wrapping body (`maximumNumberOfLines == 0`) needs a concrete wrap width inside stack-driven layout.
  268. private func updateWrappingTextPreferredWidths() {
  269. for field in Self.collectWrappingTextFields(in: self) {
  270. guard let parent = field.superview, parent.bounds.width > 2 else { continue }
  271. let w = parent.bounds.width
  272. if abs(field.preferredMaxLayoutWidth - w) > 0.5 {
  273. field.preferredMaxLayoutWidth = w
  274. }
  275. }
  276. }
  277. private static func collectWrappingTextFields(in root: NSView) -> [NSTextField] {
  278. var out: [NSTextField] = []
  279. func visit(_ v: NSView) {
  280. if let tf = v as? NSTextField, tf.maximumNumberOfLines == 0 {
  281. out.append(tf)
  282. }
  283. for c in v.subviews { visit(c) }
  284. }
  285. visit(root)
  286. return out
  287. }
  288. // MARK: - Composition
  289. private func buildRoot() -> NSView {
  290. switch template.family {
  291. case .modern:
  292. return buildModernFamilyDocument()
  293. case .creative:
  294. return buildCreativeFamilyDocument()
  295. case .executive:
  296. return buildExecutiveDocument()
  297. case .minimal:
  298. return buildMinimalDocument()
  299. case .professional:
  300. return buildProfessionalDocument()
  301. }
  302. }
  303. // MARK: - Modern (gallery uses three distinct silhouettes from `variant`)
  304. private func buildModernFamilyDocument() -> NSView {
  305. switch variant % 3 {
  306. case 0: return modernClassicBandDocument()
  307. case 1: return modernRailDocument()
  308. default: return modernSplitHeaderDocument()
  309. }
  310. }
  311. private func modernClassicBandDocument() -> NSView {
  312. let theme = template.themeColor
  313. let white = NSColor.white
  314. let nameText = displayable(profile.personal.fullName, placeholder: "Your name")
  315. let roleText = displayable(profile.personal.jobTitle, placeholder: "Professional headline")
  316. let header = NSView()
  317. header.translatesAutoresizingMaskIntoConstraints = false
  318. header.wantsLayer = true
  319. header.layer?.backgroundColor = theme.cgColor
  320. header.layer?.cornerRadius = variant % 2 == 0 ? 8 : 6
  321. let name = label(nameText, font: .systemFont(ofSize: 22, weight: .bold), color: white, maxLines: 2)
  322. let role = label(roleText, font: .systemFont(ofSize: 14, weight: .medium), color: white.withAlphaComponent(0.92), maxLines: 2)
  323. let textCol = NSStackView(views: [name, role])
  324. textCol.orientation = .vertical
  325. textCol.spacing = 4
  326. textCol.alignment = .leading
  327. textCol.translatesAutoresizingMaskIntoConstraints = false
  328. let iconRow = NSStackView()
  329. iconRow.orientation = .horizontal
  330. iconRow.spacing = 10
  331. iconRow.translatesAutoresizingMaskIntoConstraints = false
  332. for sym in ["mappin.and.ellipse", "phone.fill", "envelope.fill"] {
  333. guard let img = NSImage(systemSymbolName: sym, accessibilityDescription: nil) else { continue }
  334. let iv = NSImageView(image: img)
  335. iv.symbolConfiguration = NSImage.SymbolConfiguration(pointSize: 13, weight: .semibold)
  336. iv.contentTintColor = white.withAlphaComponent(0.88)
  337. iconRow.addArrangedSubview(iv)
  338. }
  339. let topRow = NSStackView()
  340. topRow.orientation = .horizontal
  341. topRow.spacing = 14
  342. topRow.alignment = .centerY
  343. topRow.translatesAutoresizingMaskIntoConstraints = false
  344. topRow.addArrangedSubview(textCol)
  345. topRow.addArrangedSubview(NSView())
  346. topRow.addArrangedSubview(iconRow)
  347. header.addSubview(topRow)
  348. NSLayoutConstraint.activate([
  349. topRow.leadingAnchor.constraint(equalTo: header.leadingAnchor, constant: 18),
  350. topRow.trailingAnchor.constraint(equalTo: header.trailingAnchor, constant: -18),
  351. topRow.topAnchor.constraint(equalTo: header.topAnchor, constant: 14),
  352. topRow.bottomAnchor.constraint(equalTo: header.bottomAnchor, constant: -14)
  353. ])
  354. let body: NSView
  355. switch template.layout {
  356. case .singleColumn:
  357. body = modernMainContentColumn(compact: false, includeSummaryInMain: true)
  358. case .twoColumn(let side, let tinted):
  359. let main = modernMainContentColumn(compact: true, includeSummaryInMain: false)
  360. let sideCol = modernAboutHighlightsSidebar(tinted: tinted)
  361. let row = NSStackView()
  362. row.orientation = .horizontal
  363. row.spacing = 20
  364. row.alignment = .top
  365. row.translatesAutoresizingMaskIntoConstraints = false
  366. let mult: CGFloat = (variant % 4 == 2) ? 0.36 : 0.32
  367. if side == .leading {
  368. row.addArrangedSubview(sideCol)
  369. row.addArrangedSubview(main)
  370. sideCol.widthAnchor.constraint(equalTo: row.widthAnchor, multiplier: mult).isActive = true
  371. } else {
  372. row.addArrangedSubview(main)
  373. row.addArrangedSubview(sideCol)
  374. sideCol.widthAnchor.constraint(equalTo: row.widthAnchor, multiplier: mult).isActive = true
  375. }
  376. body = row
  377. }
  378. let wrap = NSStackView(views: [header, body])
  379. wrap.orientation = .vertical
  380. wrap.spacing = 18
  381. wrap.alignment = .leading
  382. return wrap
  383. }
  384. private func modernRailDocument() -> NSView {
  385. let theme = template.themeColor
  386. let rail = NSView()
  387. rail.translatesAutoresizingMaskIntoConstraints = false
  388. rail.wantsLayer = true
  389. rail.layer?.backgroundColor = theme.cgColor
  390. rail.layer?.cornerRadius = 2
  391. rail.widthAnchor.constraint(equalToConstant: 3 + CGFloat(variant % 2)).isActive = true
  392. let inner = NSStackView()
  393. inner.orientation = .vertical
  394. inner.spacing = 10
  395. inner.alignment = .leading
  396. inner.translatesAutoresizingMaskIntoConstraints = false
  397. let nameText = displayable(profile.personal.fullName, placeholder: "Your name")
  398. let roleText = displayable(profile.personal.jobTitle, placeholder: "Professional headline")
  399. let contactParts = [profile.personal.email, profile.personal.phone].filter { !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }
  400. let contactLine = contactParts.isEmpty ? "Add contact in your profile" : contactParts.joined(separator: " · ")
  401. inner.addArrangedSubview(label(nameText, font: .systemFont(ofSize: 21, weight: .bold), color: style.ink, maxLines: 2))
  402. inner.addArrangedSubview(label(roleText, font: .systemFont(ofSize: 14, weight: .semibold), color: theme, maxLines: 2))
  403. inner.addArrangedSubview(label(contactLine, font: style.contactFont, color: style.muted, maxLines: 2))
  404. inner.addArrangedSubview(hairline())
  405. inner.addArrangedSubview(skillTagRow(theme: theme, maxTags: 5))
  406. inner.addArrangedSubview(modernPrimaryBody(theme: theme))
  407. let row = NSStackView(views: [rail, inner])
  408. row.orientation = .horizontal
  409. row.spacing = 14
  410. row.alignment = .top
  411. return row
  412. }
  413. private func modernSplitHeaderDocument() -> NSView {
  414. let theme = template.themeColor
  415. let nameText = displayable(profile.personal.fullName, placeholder: "Your name")
  416. let roleText = displayable(profile.personal.jobTitle, placeholder: "Professional headline")
  417. let loc = profile.personal.address.trimmingCharacters(in: .whitespacesAndNewlines)
  418. let left = NSStackView()
  419. left.orientation = .vertical
  420. left.spacing = 5
  421. left.alignment = .leading
  422. left.addArrangedSubview(label(nameText, font: .systemFont(ofSize: 21, weight: .bold), color: style.ink, maxLines: 2))
  423. left.addArrangedSubview(label(roleText, font: .systemFont(ofSize: 13.5, weight: .medium), color: style.muted, maxLines: 2))
  424. if !loc.isEmpty {
  425. left.addArrangedSubview(label(loc, font: style.contactFont, color: style.muted.withAlphaComponent(0.88), maxLines: 2))
  426. }
  427. let right = NSStackView()
  428. right.orientation = .vertical
  429. right.spacing = 8
  430. right.alignment = .leading
  431. right.wantsLayer = true
  432. right.layer?.backgroundColor = theme.cgColor
  433. right.layer?.cornerRadius = 8
  434. right.edgeInsets = NSEdgeInsets(top: 14, left: 14, bottom: 14, right: 14)
  435. let onW = NSColor.white
  436. if !profile.personal.email.isEmpty {
  437. right.addArrangedSubview(label(profile.personal.email, font: .systemFont(ofSize: 12, weight: .medium), color: onW.withAlphaComponent(0.95), maxLines: 2))
  438. }
  439. if !profile.personal.phone.isEmpty {
  440. right.addArrangedSubview(label(profile.personal.phone, font: .systemFont(ofSize: 12, weight: .medium), color: onW.withAlphaComponent(0.92), maxLines: 1))
  441. }
  442. if !loc.isEmpty {
  443. right.addArrangedSubview(label(loc, font: .systemFont(ofSize: 11.5, weight: .regular), color: onW.withAlphaComponent(0.8), maxLines: 2))
  444. }
  445. let top = NSStackView(views: [left, right])
  446. top.orientation = .horizontal
  447. top.spacing = 16
  448. top.alignment = .top
  449. left.widthAnchor.constraint(equalTo: top.widthAnchor, multiplier: 0.54).isActive = true
  450. let col = NSStackView(views: [top, hairline(), modernPrimaryBody(theme: theme)])
  451. col.orientation = .vertical
  452. col.spacing = 16
  453. col.alignment = .leading
  454. return col
  455. }
  456. private func modernPrimaryBody(theme: NSColor) -> NSView {
  457. switch template.layout {
  458. case .singleColumn:
  459. return modernMainContentColumn(compact: false, includeSummaryInMain: true)
  460. case .twoColumn(let side, let tinted):
  461. let main = modernMainContentColumn(compact: true, includeSummaryInMain: false)
  462. let sideCol = modernAboutHighlightsSidebar(tinted: tinted)
  463. let row = NSStackView()
  464. row.orientation = .horizontal
  465. row.spacing = 20
  466. row.alignment = .top
  467. let mult: CGFloat = (variant % 4 == 2) ? 0.36 : 0.32
  468. if side == .leading {
  469. row.addArrangedSubview(sideCol)
  470. row.addArrangedSubview(main)
  471. sideCol.widthAnchor.constraint(equalTo: row.widthAnchor, multiplier: mult).isActive = true
  472. } else {
  473. row.addArrangedSubview(main)
  474. row.addArrangedSubview(sideCol)
  475. sideCol.widthAnchor.constraint(equalTo: row.widthAnchor, multiplier: mult).isActive = true
  476. }
  477. return row
  478. }
  479. }
  480. private func modernMainContentColumn(compact: Bool, includeSummaryInMain: Bool) -> NSView {
  481. let theme = template.themeColor
  482. let v = NSStackView()
  483. v.orientation = .vertical
  484. v.spacing = compact ? style.bodyBlockSpacing : style.bodyBlockSpacing + 2
  485. v.alignment = .leading
  486. if includeSummaryInMain, let summary = nonEmpty(profile.careerSummary) {
  487. v.addArrangedSubview(modernSectionRow(symbol: "person.crop.circle", title: "About", theme: theme))
  488. v.addArrangedSubview(paragraph(summary, compact: compact))
  489. }
  490. let jobs = profile.workExperiences.filter { !$0.isEffectivelyEmpty }
  491. if !jobs.isEmpty {
  492. v.addArrangedSubview(modernSectionRow(symbol: "briefcase.fill", title: "Experience", theme: theme))
  493. for (index, job) in jobs.enumerated() {
  494. v.addArrangedSubview(experienceBlock(job: job, compact: compact))
  495. if index == 0 {
  496. v.addArrangedSubview(skillTagRow(theme: theme, maxTags: 5))
  497. }
  498. }
  499. }
  500. let schools = profile.educations.filter { !$0.isEffectivelyEmpty }
  501. if !schools.isEmpty {
  502. v.addArrangedSubview(modernSectionRow(symbol: "graduationcap.fill", title: "Education", theme: theme))
  503. for edu in schools {
  504. v.addArrangedSubview(educationBlock(edu: edu, compact: compact))
  505. }
  506. }
  507. appendCertificatesInterestsReferrals(to: v, compact: compact)
  508. return v
  509. }
  510. private func modernAboutHighlightsSidebar(tinted: Bool) -> NSView {
  511. let theme = template.themeColor
  512. let box = NSStackView()
  513. box.orientation = .vertical
  514. box.spacing = 12
  515. box.alignment = .leading
  516. if tinted {
  517. box.wantsLayer = true
  518. box.layer?.backgroundColor = theme.withAlphaComponent(0.1).cgColor
  519. box.layer?.cornerRadius = 8
  520. box.edgeInsets = NSEdgeInsets(top: 14, left: 14, bottom: 14, right: 14)
  521. }
  522. if let summary = nonEmpty(profile.careerSummary) {
  523. box.addArrangedSubview(modernSectionRow(symbol: "person.crop.circle", title: "About", theme: theme))
  524. box.addArrangedSubview(paragraph(summary, compact: true))
  525. }
  526. if let hi = highlightsBodyText() {
  527. box.addArrangedSubview(modernSectionRow(symbol: "star.fill", title: "Highlights", theme: theme))
  528. box.addArrangedSubview(paragraph(hi, compact: true))
  529. }
  530. if box.arrangedSubviews.isEmpty {
  531. box.addArrangedSubview(modernSectionRow(symbol: "person.crop.circle", title: "About", theme: theme))
  532. box.addArrangedSubview(paragraph("Add a career summary or interests in your profile to populate this column.", compact: true))
  533. }
  534. return box
  535. }
  536. private func modernSectionRow(symbol: String, title: String, theme: NSColor) -> NSView {
  537. guard let img = NSImage(systemSymbolName: symbol, accessibilityDescription: nil) else {
  538. return sectionHeading(title)
  539. }
  540. let iv = NSImageView(image: img)
  541. iv.symbolConfiguration = NSImage.SymbolConfiguration(pointSize: 12, weight: .semibold)
  542. iv.contentTintColor = theme
  543. let t = label(title.uppercased(), font: style.sectionFont, color: style.ink, maxLines: 1)
  544. let r = NSStackView(views: [iv, t])
  545. r.orientation = .horizontal
  546. r.spacing = 8
  547. r.alignment = .centerY
  548. return r
  549. }
  550. private func skillTagRow(theme: NSColor, maxTags: Int) -> NSView {
  551. let tags = skillTokensFromProfile(max: maxTags)
  552. guard !tags.isEmpty else { return NSView() }
  553. let row = NSStackView()
  554. row.orientation = .horizontal
  555. row.spacing = 8
  556. row.alignment = .centerY
  557. for s in tags {
  558. let tag = NSView()
  559. tag.wantsLayer = true
  560. tag.layer?.backgroundColor = theme.withAlphaComponent(0.14).cgColor
  561. tag.layer?.cornerRadius = 6
  562. tag.translatesAutoresizingMaskIntoConstraints = false
  563. let lab = label(s, font: .systemFont(ofSize: 11, weight: .semibold), color: theme.blended(withFraction: 0.35, of: style.ink) ?? style.ink, maxLines: 1)
  564. lab.alignment = .center
  565. lab.translatesAutoresizingMaskIntoConstraints = false
  566. tag.addSubview(lab)
  567. NSLayoutConstraint.activate([
  568. lab.leadingAnchor.constraint(equalTo: tag.leadingAnchor, constant: 10),
  569. lab.trailingAnchor.constraint(equalTo: tag.trailingAnchor, constant: -10),
  570. lab.topAnchor.constraint(equalTo: tag.topAnchor, constant: 5),
  571. lab.bottomAnchor.constraint(equalTo: tag.bottomAnchor, constant: -5)
  572. ])
  573. row.addArrangedSubview(tag)
  574. }
  575. return row
  576. }
  577. // MARK: - Creative (dark sidebar in gallery — match filled page)
  578. private func buildCreativeFamilyDocument() -> NSView {
  579. switch template.layout {
  580. case .singleColumn:
  581. return creativeSingleColumnDocument()
  582. case .twoColumn(let side, _):
  583. return creativeTwoColumnDocument(sidebar: side)
  584. }
  585. }
  586. private func creativeDeepBackground() -> NSColor {
  587. let theme = template.themeColor
  588. let navy = NSColor(srgbRed: 0.08, green: 0.1, blue: 0.18, alpha: 1)
  589. let plum = NSColor(srgbRed: 0.14, green: 0.07, blue: 0.24, alpha: 1)
  590. switch variant % 4 {
  591. case 0: return theme.blended(withFraction: 0.52, of: navy) ?? theme
  592. case 1: return theme.blended(withFraction: 0.7, of: NSColor.black) ?? theme
  593. case 2: return style.ink.blended(withFraction: 0.38, of: theme) ?? theme
  594. default: return theme.blended(withFraction: 0.4, of: plum) ?? theme
  595. }
  596. }
  597. private func creativeSingleColumnDocument() -> NSView {
  598. let theme = template.themeColor
  599. let nameText = displayable(profile.personal.fullName, placeholder: "Your name")
  600. let roleText = displayable(profile.personal.jobTitle, placeholder: "Professional headline")
  601. let banner = NSView()
  602. banner.translatesAutoresizingMaskIntoConstraints = false
  603. banner.wantsLayer = true
  604. banner.layer?.backgroundColor = theme.cgColor
  605. banner.layer?.cornerRadius = variant % 4 == 1 ? 8 : 6
  606. let inner = label(" \(nameText) · \(roleText) ", font: .systemFont(ofSize: 14, weight: .bold), color: .white, maxLines: 2)
  607. inner.translatesAutoresizingMaskIntoConstraints = false
  608. banner.addSubview(inner)
  609. NSLayoutConstraint.activate([
  610. inner.leadingAnchor.constraint(equalTo: banner.leadingAnchor, constant: 14),
  611. inner.trailingAnchor.constraint(lessThanOrEqualTo: banner.trailingAnchor, constant: -14),
  612. inner.topAnchor.constraint(equalTo: banner.topAnchor, constant: 12),
  613. inner.bottomAnchor.constraint(equalTo: banner.bottomAnchor, constant: -12)
  614. ])
  615. let main = creativeMainStack(theme: theme)
  616. let col = NSStackView(views: [banner, main])
  617. col.orientation = .vertical
  618. col.spacing = 16
  619. col.alignment = .leading
  620. return col
  621. }
  622. private func creativeTwoColumnDocument(sidebar: CVTemplate.SidebarSide) -> NSView {
  623. let theme = template.themeColor
  624. let deep = creativeDeepBackground()
  625. let onSidebar = NSColor.white.withAlphaComponent(0.95)
  626. let skillPrefix = (variant % 3 == 0) ? "• " : "▸ "
  627. let sidebarStack = NSStackView()
  628. sidebarStack.orientation = .vertical
  629. sidebarStack.spacing = 12
  630. sidebarStack.alignment = .leading
  631. sidebarStack.wantsLayer = true
  632. sidebarStack.layer?.backgroundColor = deep.cgColor
  633. sidebarStack.layer?.cornerRadius = variant % 2 == 0 ? 10 : 8
  634. sidebarStack.edgeInsets = NSEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
  635. let nm = displayable(profile.personal.fullName, placeholder: "Your name")
  636. let role = displayable(profile.personal.jobTitle, placeholder: "Professional headline")
  637. sidebarStack.addArrangedSubview(label(nm, font: .systemFont(ofSize: 18, weight: .bold), color: onSidebar, maxLines: 2))
  638. sidebarStack.addArrangedSubview(label(role, font: .systemFont(ofSize: 13, weight: .medium), color: onSidebar.withAlphaComponent(0.85), maxLines: 2))
  639. if !profile.personal.email.isEmpty {
  640. sidebarStack.addArrangedSubview(label(profile.personal.email, font: .systemFont(ofSize: 11.5), color: onSidebar.withAlphaComponent(0.82), maxLines: 2))
  641. }
  642. if !profile.personal.phone.isEmpty {
  643. sidebarStack.addArrangedSubview(label(profile.personal.phone, font: .systemFont(ofSize: 11.5), color: onSidebar.withAlphaComponent(0.82), maxLines: 1))
  644. }
  645. sidebarStack.addArrangedSubview(creativeSidebarHeading("STRENGTHS", onSidebar: onSidebar, accent: theme))
  646. for token in skillTokensFromProfile(max: 8) {
  647. sidebarStack.addArrangedSubview(label("\(skillPrefix)\(token)", font: .systemFont(ofSize: 12, weight: .semibold), color: onSidebar.withAlphaComponent(0.92), maxLines: 2))
  648. }
  649. let main = creativeMainStack(theme: theme)
  650. let row = NSStackView()
  651. row.orientation = .horizontal
  652. row.spacing = 18
  653. row.alignment = .top
  654. let sidebarMult = 0.32 + CGFloat(variant % 3) * 0.02
  655. if sidebar == .leading {
  656. row.addArrangedSubview(sidebarStack)
  657. row.addArrangedSubview(main)
  658. sidebarStack.widthAnchor.constraint(equalTo: row.widthAnchor, multiplier: sidebarMult).isActive = true
  659. } else {
  660. row.addArrangedSubview(main)
  661. row.addArrangedSubview(sidebarStack)
  662. sidebarStack.widthAnchor.constraint(equalTo: row.widthAnchor, multiplier: sidebarMult).isActive = true
  663. }
  664. return row
  665. }
  666. private func creativeSidebarHeading(_ raw: String, onSidebar: NSColor, accent: NSColor) -> NSView {
  667. let t = label(raw, font: .systemFont(ofSize: 10.5, weight: .heavy), color: onSidebar, maxLines: 1)
  668. let bar = NSView()
  669. bar.translatesAutoresizingMaskIntoConstraints = false
  670. bar.wantsLayer = true
  671. bar.layer?.backgroundColor = accent.cgColor
  672. bar.heightAnchor.constraint(equalToConstant: 2).isActive = true
  673. let c = NSStackView(views: [t, bar])
  674. c.orientation = .vertical
  675. c.spacing = 4
  676. c.alignment = .leading
  677. bar.leadingAnchor.constraint(equalTo: t.leadingAnchor).isActive = true
  678. bar.widthAnchor.constraint(equalToConstant: 72).isActive = true
  679. return c
  680. }
  681. private func creativeMainHeader(theme: NSColor) -> NSView {
  682. let v = NSView()
  683. v.translatesAutoresizingMaskIntoConstraints = false
  684. let stripe = NSView()
  685. stripe.translatesAutoresizingMaskIntoConstraints = false
  686. stripe.wantsLayer = true
  687. stripe.layer?.backgroundColor = theme.cgColor
  688. v.addSubview(stripe)
  689. let row = NSStackView()
  690. row.orientation = .horizontal
  691. row.spacing = 8
  692. row.translatesAutoresizingMaskIntoConstraints = false
  693. let lab = label("PORTFOLIO SNAPSHOT", font: .systemFont(ofSize: 12, weight: .heavy), color: style.ink, maxLines: 1)
  694. row.addArrangedSubview(stripe)
  695. row.addArrangedSubview(lab)
  696. v.addSubview(row)
  697. NSLayoutConstraint.activate([
  698. stripe.widthAnchor.constraint(equalToConstant: 4),
  699. stripe.heightAnchor.constraint(equalToConstant: 18),
  700. row.leadingAnchor.constraint(equalTo: v.leadingAnchor),
  701. row.topAnchor.constraint(equalTo: v.topAnchor),
  702. row.bottomAnchor.constraint(equalTo: v.bottomAnchor)
  703. ])
  704. return v
  705. }
  706. private func creativeMainStack(theme: NSColor) -> NSView {
  707. let stack = NSStackView()
  708. stack.orientation = .vertical
  709. stack.spacing = style.bodyBlockSpacing
  710. stack.alignment = .leading
  711. stack.addArrangedSubview(creativeMainHeader(theme: theme))
  712. if let summary = nonEmpty(profile.careerSummary) {
  713. stack.addArrangedSubview(sectionHeading("Profile"))
  714. stack.addArrangedSubview(paragraph(summary, compact: false))
  715. }
  716. let jobs = profile.workExperiences.filter { !$0.isEffectivelyEmpty }
  717. if !jobs.isEmpty {
  718. stack.addArrangedSubview(sectionHeading("Impact"))
  719. for job in jobs {
  720. let titleLine = [job.jobTitle, job.company].filter { !$0.isEmpty }.joined(separator: " — ")
  721. if !titleLine.isEmpty {
  722. stack.addArrangedSubview(label(titleLine, font: .systemFont(ofSize: 13.5, weight: .heavy), color: style.ink, maxLines: 0))
  723. }
  724. for bullet in Self.bulletChunks(from: job.description) {
  725. let mark = (variant % 2 == 0) ? "— " : "▸ "
  726. stack.addArrangedSubview(label("\(mark)\(bullet)", font: style.bodyFont, color: style.muted, maxLines: 0))
  727. }
  728. }
  729. }
  730. let schools = profile.educations.filter { !$0.isEffectivelyEmpty }
  731. if !schools.isEmpty {
  732. stack.addArrangedSubview(sectionHeading("Education"))
  733. for edu in schools {
  734. stack.addArrangedSubview(educationBlock(edu: edu, compact: false))
  735. }
  736. }
  737. appendCertificatesInterestsReferrals(to: stack, compact: false)
  738. return stack
  739. }
  740. // MARK: - Executive (matches gallery serif layout)
  741. private func buildExecutiveDocument() -> NSView {
  742. let centeredHead = (variant % 2) == 0
  743. let nameText = displayable(profile.personal.fullName, placeholder: "Your name")
  744. let roleText = displayable(profile.personal.jobTitle, placeholder: "Professional headline")
  745. let contactParts = [profile.personal.email, profile.personal.phone, profile.personal.address].filter {
  746. !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
  747. }
  748. let contactText = contactParts.isEmpty ? "Add contact details in your profile" : contactParts.joined(separator: " · ")
  749. let name = label(nameText, font: style.nameFont, color: style.ink, maxLines: 2)
  750. let role = label(roleText, font: style.roleFont, color: style.muted, maxLines: 2)
  751. let contact = label(contactText, font: style.contactFont, color: style.muted.withAlphaComponent(0.9), maxLines: 3)
  752. if centeredHead {
  753. name.alignment = .center
  754. role.alignment = .center
  755. contact.alignment = .center
  756. }
  757. let rule = executiveHeaderRule(wide: variant % 3 == 0)
  758. let head = NSStackView(views: [name, role, contact, rule])
  759. head.orientation = .vertical
  760. head.spacing = 8
  761. head.alignment = centeredHead ? .centerX : .leading
  762. let body: NSView
  763. switch template.layout {
  764. case .singleColumn:
  765. body = executiveMainColumn(compact: false, tightLeading: variant % 5 == 2)
  766. case .twoColumn(let side, let tinted):
  767. let main = executiveMainColumn(compact: true, tightLeading: variant % 5 == 2)
  768. let sideCol = executiveSidebarColumn(tinted: tinted, showMetrics: variant % 4 == 1)
  769. let row = NSStackView()
  770. row.orientation = .horizontal
  771. row.spacing = 20
  772. row.alignment = .top
  773. if side == .leading {
  774. row.addArrangedSubview(sideCol)
  775. row.addArrangedSubview(main)
  776. } else {
  777. row.addArrangedSubview(main)
  778. row.addArrangedSubview(sideCol)
  779. }
  780. let mult: CGFloat = (variant % 5 == 3) ? 0.38 : 0.33
  781. sideCol.widthAnchor.constraint(equalTo: row.widthAnchor, multiplier: mult).isActive = true
  782. body = row
  783. }
  784. let wrap = NSStackView(views: [head, body])
  785. wrap.orientation = .vertical
  786. wrap.spacing = style.columnVerticalSpacing
  787. wrap.alignment = .leading
  788. return wrap
  789. }
  790. private func executiveHeaderRule(wide: Bool) -> NSView {
  791. let theme = template.themeColor
  792. let v = NSView()
  793. v.translatesAutoresizingMaskIntoConstraints = false
  794. v.wantsLayer = true
  795. v.layer?.backgroundColor = theme.withAlphaComponent(0.45).cgColor
  796. v.heightAnchor.constraint(equalToConstant: wide ? 2 : 1.5).isActive = true
  797. v.widthAnchor.constraint(equalToConstant: wide ? 160 : 110).isActive = true
  798. return v
  799. }
  800. private func executiveMainColumn(compact: Bool, tightLeading: Bool) -> NSView {
  801. let stack = NSStackView()
  802. stack.orientation = .vertical
  803. stack.spacing = (compact ? style.bodyBlockSpacing : style.bodyBlockSpacing + 2) - (tightLeading ? 2 : 0)
  804. stack.alignment = .leading
  805. let summaryTitle = (variant % 6 == 3) ? "Summary" : "Professional Summary"
  806. if let summary = nonEmpty(profile.careerSummary) {
  807. stack.addArrangedSubview(sectionHeading(summaryTitle))
  808. stack.addArrangedSubview(paragraph(summary, compact: compact))
  809. }
  810. let jobs = profile.workExperiences.filter { !$0.isEffectivelyEmpty }
  811. if !jobs.isEmpty {
  812. stack.addArrangedSubview(sectionHeading("Selected Experience"))
  813. for job in jobs {
  814. stack.addArrangedSubview(executiveExperienceBlock(job: job, compact: compact))
  815. }
  816. }
  817. let schools = profile.educations.filter { !$0.isEffectivelyEmpty }
  818. if !schools.isEmpty {
  819. stack.addArrangedSubview(sectionHeading("Education"))
  820. for edu in schools {
  821. stack.addArrangedSubview(educationBlock(edu: edu, compact: compact))
  822. }
  823. }
  824. appendCertificatesInterestsReferrals(to: stack, compact: compact)
  825. return stack
  826. }
  827. private func executiveExperienceBlock(job: WorkExperiencePayload, compact: Bool) -> NSView {
  828. let v = NSStackView()
  829. v.orientation = .vertical
  830. v.spacing = 4
  831. v.alignment = .leading
  832. let titleLine = [job.jobTitle, job.company].filter { !$0.isEmpty }.joined(separator: ", ")
  833. if !titleLine.isEmpty {
  834. v.addArrangedSubview(label(titleLine, font: style.expTitleFont, color: style.ink, maxLines: 0))
  835. }
  836. let duration = job.duration.trimmingCharacters(in: .whitespacesAndNewlines)
  837. if !duration.isEmpty {
  838. v.addArrangedSubview(label(duration, font: style.expMetaFont, color: template.themeColor, maxLines: 0))
  839. }
  840. for bullet in Self.bulletChunks(from: job.description) {
  841. v.addArrangedSubview(label(bullet, font: style.bodyFont, color: style.muted, maxLines: 0))
  842. }
  843. return v
  844. }
  845. private func executiveSidebarColumn(tinted: Bool, showMetrics: Bool) -> NSView {
  846. let stack = NSStackView()
  847. stack.orientation = .vertical
  848. stack.spacing = 10
  849. stack.alignment = .leading
  850. if tinted {
  851. stack.wantsLayer = true
  852. let fill = (variant % 3 == 0)
  853. ? CVResumeAppearance.colors().sidebarTint
  854. : template.themeColor.withAlphaComponent(0.07)
  855. stack.layer?.backgroundColor = fill.cgColor
  856. stack.layer?.cornerRadius = variant % 4 == 2 ? 8 : 6
  857. stack.edgeInsets = NSEdgeInsets(top: 14, left: 14, bottom: 14, right: 14)
  858. }
  859. let skills = skillTokensFromProfile(max: 12)
  860. if !skills.isEmpty {
  861. stack.addArrangedSubview(sectionHeading("Core Competencies"))
  862. for s in skills {
  863. stack.addArrangedSubview(label("· \(s)", font: style.bodyFont, color: style.ink, maxLines: 0))
  864. }
  865. }
  866. if let cert = nonEmpty(profile.certificates) {
  867. stack.addArrangedSubview(sectionHeading("Tools"))
  868. stack.addArrangedSubview(paragraph(cert, compact: true))
  869. }
  870. if showMetrics, let hi = highlightsBodyText() {
  871. stack.addArrangedSubview(sectionHeading("Impact"))
  872. stack.addArrangedSubview(paragraph(hi, compact: true))
  873. }
  874. if stack.arrangedSubviews.isEmpty {
  875. stack.addArrangedSubview(sectionHeading("Contact"))
  876. for line in contactLines() {
  877. stack.addArrangedSubview(label(line, font: style.contactFont, color: style.ink, maxLines: 0))
  878. }
  879. }
  880. return stack
  881. }
  882. // MARK: - Minimal (matches gallery light typography)
  883. private func buildMinimalDocument() -> NSView {
  884. let nameText = displayable(profile.personal.fullName, placeholder: "Your name")
  885. let roleText = displayable(profile.personal.jobTitle, placeholder: "Professional headline")
  886. let contactParts = [profile.personal.email, profile.personal.phone].filter {
  887. !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
  888. }
  889. let contactText = contactParts.isEmpty ? "Add contact in your profile" : contactParts.joined(separator: " ")
  890. let nameWeight: NSFont.Weight = (variant % 3 == 0) ? .ultraLight : .light
  891. let nameSize: CGFloat = template.headline == .centered ? 22 + CGFloat(variant % 2) : 20 + CGFloat(variant % 3)
  892. let name = label(nameText, font: .systemFont(ofSize: nameSize, weight: nameWeight), color: style.ink, maxLines: 2)
  893. let role = label(roleText.uppercased(), font: .systemFont(ofSize: 12.5, weight: .medium), color: style.muted, maxLines: 2)
  894. let contact = label(contactText, font: style.contactFont, color: style.muted.withAlphaComponent(0.75), maxLines: 2)
  895. let head = NSStackView()
  896. head.orientation = .vertical
  897. head.spacing = template.headline == .avatarStacked ? 10 : 6 + CGFloat(variant % 4)
  898. head.alignment = template.headline == .centered ? .centerX : .leading
  899. if template.headline == .avatarStacked {
  900. head.addArrangedSubview(initialsBadge(for: nameText))
  901. }
  902. if template.headline == .centered {
  903. name.alignment = .center
  904. role.alignment = .center
  905. contact.alignment = .center
  906. }
  907. head.addArrangedSubview(name)
  908. head.addArrangedSubview(role)
  909. head.addArrangedSubview(contact)
  910. head.addArrangedSubview(hairline())
  911. if variant % 5 == 1 {
  912. head.addArrangedSubview(hairline())
  913. }
  914. let swapEdu = (variant % 4) == 2
  915. let body: NSView
  916. switch template.layout {
  917. case .singleColumn:
  918. body = minimalMainColumn(spacing: style.bodyBlockSpacing, educationBeforeExperience: swapEdu)
  919. case .twoColumn(let side, _):
  920. let main = minimalMainColumn(spacing: style.bodyBlockSpacing - 2, educationBeforeExperience: swapEdu)
  921. let aside = minimalSkillsAside(numbered: variant % 3 == 1)
  922. let row = NSStackView()
  923. row.orientation = .horizontal
  924. row.spacing = 18 + CGFloat(variant % 3)
  925. row.alignment = .top
  926. if side == .leading {
  927. row.addArrangedSubview(aside)
  928. row.addArrangedSubview(main)
  929. } else {
  930. row.addArrangedSubview(main)
  931. row.addArrangedSubview(aside)
  932. }
  933. let mult: CGFloat = (variant % 5 == 0) ? 0.34 : 0.30
  934. aside.widthAnchor.constraint(equalTo: row.widthAnchor, multiplier: mult).isActive = true
  935. body = row
  936. }
  937. let wrap = NSStackView(views: [head, body])
  938. wrap.orientation = .vertical
  939. wrap.spacing = style.columnVerticalSpacing
  940. wrap.alignment = .leading
  941. return wrap
  942. }
  943. private func minimalMainColumn(spacing: CGFloat, educationBeforeExperience: Bool) -> NSView {
  944. let stack = NSStackView()
  945. stack.orientation = .vertical
  946. stack.spacing = spacing
  947. stack.alignment = .leading
  948. let appendSummary: () -> Void = { [self] in
  949. if let summary = nonEmpty(profile.careerSummary) {
  950. stack.addArrangedSubview(sectionHeading("Profile"))
  951. stack.addArrangedSubview(paragraph(summary, compact: false))
  952. }
  953. }
  954. let appendExperience: () -> Void = { [self] in
  955. let jobs = profile.workExperiences.filter { !$0.isEffectivelyEmpty }
  956. if !jobs.isEmpty {
  957. stack.addArrangedSubview(sectionHeading("Experience"))
  958. for job in jobs {
  959. stack.addArrangedSubview(experienceBlock(job: job, compact: false))
  960. }
  961. }
  962. }
  963. let appendEducation: () -> Void = { [self] in
  964. let schools = profile.educations.filter { !$0.isEffectivelyEmpty }
  965. if !schools.isEmpty {
  966. stack.addArrangedSubview(sectionHeading("Education"))
  967. for edu in schools {
  968. stack.addArrangedSubview(educationBlock(edu: edu, compact: false))
  969. }
  970. }
  971. }
  972. if educationBeforeExperience {
  973. appendEducation()
  974. appendSummary()
  975. appendExperience()
  976. } else {
  977. appendSummary()
  978. appendExperience()
  979. appendEducation()
  980. }
  981. appendCertificatesInterestsReferrals(to: stack, compact: false)
  982. return stack
  983. }
  984. private func minimalSkillsAside(numbered: Bool) -> NSView {
  985. let stack = NSStackView()
  986. stack.orientation = .vertical
  987. stack.spacing = 8
  988. stack.alignment = .leading
  989. let skills = skillTokensFromProfile(max: 12)
  990. if skills.isEmpty {
  991. stack.addArrangedSubview(sectionHeading("Contact"))
  992. for line in contactLines() {
  993. stack.addArrangedSubview(label(line, font: style.contactFont, color: style.muted, maxLines: 0))
  994. }
  995. return stack
  996. }
  997. stack.addArrangedSubview(sectionHeading("Skills"))
  998. for (i, s) in skills.enumerated() {
  999. let prefix = numbered ? "\(i + 1). " : "· "
  1000. stack.addArrangedSubview(label("\(prefix)\(s)", font: style.bodyCompactFont, color: style.muted, maxLines: 0))
  1001. }
  1002. return stack
  1003. }
  1004. // MARK: - Professional
  1005. private func buildProfessionalDocument() -> NSView {
  1006. switch template.layout {
  1007. case .singleColumn:
  1008. return singleColumnLayout()
  1009. case .twoColumn(let side, let tinted):
  1010. return twoColumnLayout(sidebar: side, tinted: tinted)
  1011. }
  1012. }
  1013. private func singleColumnLayout() -> NSView {
  1014. let v = NSStackView()
  1015. v.orientation = .vertical
  1016. v.alignment = .leading
  1017. v.spacing = style.columnVerticalSpacing + 3
  1018. v.addArrangedSubview(headerBlock())
  1019. if template.family == .professional && (variant % 6) == 4 {
  1020. v.addArrangedSubview(professionalInlineSkillsRow())
  1021. }
  1022. v.addArrangedSubview(hairline())
  1023. let body = bodyColumn(compact: false, experienceFirst: professionalExperienceFirst)
  1024. v.addArrangedSubview(usesProfessionalSingleColumnRail ? bodyWithLeadingAccentRail(body) : body)
  1025. return v
  1026. }
  1027. private var professionalExperienceFirst: Bool {
  1028. template.family == .professional && (variant % 3) == 1
  1029. }
  1030. private func professionalInlineSkillsRow() -> NSView {
  1031. let tokens = skillTokensFromProfile(max: 6)
  1032. guard !tokens.isEmpty else { return NSView() }
  1033. let joined = tokens.joined(separator: " · ")
  1034. return label(joined, font: .systemFont(ofSize: 11.5, weight: .medium), color: template.themeColor, maxLines: 0)
  1035. }
  1036. /// Matches the CV Maker thumbnail: professional ATS single-column layouts use a full-height theme rail.
  1037. private var usesProfessionalSingleColumnRail: Bool {
  1038. if case .singleColumn = template.layout, template.family == .professional { return true }
  1039. return false
  1040. }
  1041. private func bodyWithLeadingAccentRail(_ content: NSView) -> NSView {
  1042. let wrap = NSView()
  1043. wrap.translatesAutoresizingMaskIntoConstraints = false
  1044. let rail = NSView()
  1045. rail.translatesAutoresizingMaskIntoConstraints = false
  1046. rail.wantsLayer = true
  1047. rail.layer?.backgroundColor = template.themeColor.cgColor
  1048. rail.layer?.cornerRadius = 1
  1049. content.translatesAutoresizingMaskIntoConstraints = false
  1050. wrap.addSubview(rail)
  1051. wrap.addSubview(content)
  1052. NSLayoutConstraint.activate([
  1053. rail.leadingAnchor.constraint(equalTo: wrap.leadingAnchor),
  1054. rail.topAnchor.constraint(equalTo: content.topAnchor),
  1055. rail.bottomAnchor.constraint(equalTo: content.bottomAnchor),
  1056. rail.widthAnchor.constraint(equalToConstant: 3),
  1057. content.leadingAnchor.constraint(equalTo: rail.trailingAnchor, constant: 12),
  1058. content.trailingAnchor.constraint(equalTo: wrap.trailingAnchor),
  1059. content.topAnchor.constraint(equalTo: wrap.topAnchor),
  1060. content.bottomAnchor.constraint(equalTo: wrap.bottomAnchor)
  1061. ])
  1062. return wrap
  1063. }
  1064. private func twoColumnLayout(sidebar: CVTemplate.SidebarSide, tinted: Bool) -> NSView {
  1065. let v = NSStackView()
  1066. v.orientation = .vertical
  1067. v.alignment = .leading
  1068. v.spacing = style.columnVerticalSpacing + 2
  1069. v.addArrangedSubview(headerBlock())
  1070. v.addArrangedSubview(hairline())
  1071. let row = NSStackView()
  1072. row.orientation = .horizontal
  1073. row.alignment = .top
  1074. row.spacing = 22
  1075. let sidebarCol = sidebarColumn(tinted: tinted)
  1076. let mainCol = bodyColumn(compact: true, experienceFirst: professionalExperienceFirst)
  1077. if sidebar == .leading {
  1078. row.addArrangedSubview(sidebarCol)
  1079. row.addArrangedSubview(mainCol)
  1080. } else {
  1081. row.addArrangedSubview(mainCol)
  1082. row.addArrangedSubview(sidebarCol)
  1083. }
  1084. let sidebarMult: CGFloat = (variant % 5 == 2) ? 0.38 : 0.32
  1085. sidebarCol.widthAnchor.constraint(equalTo: row.widthAnchor, multiplier: sidebarMult).isActive = true
  1086. v.addArrangedSubview(row)
  1087. return v
  1088. }
  1089. private func headerBlock() -> NSView {
  1090. let nameText = displayable(profile.personal.fullName, placeholder: "Your name")
  1091. let roleText = displayable(profile.personal.jobTitle, placeholder: "Professional headline")
  1092. let contactParts = [profile.personal.email, profile.personal.phone, profile.personal.address].filter { !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }
  1093. let contactText = contactParts.isEmpty ? "Add contact details in your profile" : contactParts.joined(separator: " · ")
  1094. let roleColor = style.roleUsesThemeColor ? template.themeColor : style.muted
  1095. let name = label(nameText, font: style.nameFont, color: style.ink, maxLines: 2)
  1096. let role = label(roleText, font: style.roleFont, color: roleColor, maxLines: 2)
  1097. let contact = label(contactText, font: style.contactFont, color: style.muted.withAlphaComponent(0.92), maxLines: 3)
  1098. let textCol = NSStackView(views: [name, role, contact])
  1099. textCol.orientation = .vertical
  1100. textCol.spacing = template.family == .professional ? 3 : 4
  1101. textCol.alignment = .leading
  1102. switch template.headline {
  1103. case .centered:
  1104. textCol.alignment = .centerX
  1105. name.alignment = .center
  1106. role.alignment = .center
  1107. contact.alignment = .center
  1108. let accent = headlineAccent()
  1109. let stack = NSStackView(views: [textCol, accent])
  1110. stack.orientation = .vertical
  1111. stack.spacing = 8
  1112. stack.alignment = .centerX
  1113. return stack
  1114. case .avatarStacked:
  1115. textCol.alignment = .centerX
  1116. name.alignment = .center
  1117. role.alignment = .center
  1118. contact.alignment = .center
  1119. let accent = headlineAccent()
  1120. let avatar = initialsBadge(for: nameText)
  1121. let stack = NSStackView(views: [avatar, textCol, accent])
  1122. stack.orientation = .vertical
  1123. stack.spacing = 8
  1124. stack.alignment = .centerX
  1125. return stack
  1126. case .leftAligned, .leftWithInitials:
  1127. let row = NSStackView()
  1128. row.orientation = .horizontal
  1129. row.spacing = 14
  1130. row.alignment = .centerY
  1131. row.addArrangedSubview(textCol)
  1132. if template.headline == .leftWithInitials {
  1133. row.addArrangedSubview(NSView())
  1134. row.addArrangedSubview(initialsBadge(for: nameText))
  1135. }
  1136. let col = NSStackView(views: [row, headlineAccent()])
  1137. col.orientation = .vertical
  1138. col.spacing = 8
  1139. col.alignment = .leading
  1140. return col
  1141. }
  1142. }
  1143. private func initialsBadge(for fullName: String) -> NSView {
  1144. let initials = Self.initials(from: fullName)
  1145. let t = NSTextField(labelWithString: initials)
  1146. t.font = .systemFont(ofSize: 13, weight: .bold)
  1147. t.textColor = template.themeColor
  1148. t.alignment = .center
  1149. t.translatesAutoresizingMaskIntoConstraints = false
  1150. let wrap = NSView()
  1151. wrap.translatesAutoresizingMaskIntoConstraints = false
  1152. wrap.wantsLayer = true
  1153. wrap.layer?.cornerRadius = 22
  1154. wrap.layer?.borderWidth = 1.5
  1155. wrap.layer?.borderColor = template.themeColor.withAlphaComponent(0.35).cgColor
  1156. wrap.addSubview(t)
  1157. NSLayoutConstraint.activate([
  1158. wrap.widthAnchor.constraint(equalToConstant: 44),
  1159. wrap.heightAnchor.constraint(equalToConstant: 44),
  1160. t.centerXAnchor.constraint(equalTo: wrap.centerXAnchor),
  1161. t.centerYAnchor.constraint(equalTo: wrap.centerYAnchor)
  1162. ])
  1163. return wrap
  1164. }
  1165. private static func initials(from fullName: String) -> String {
  1166. let parts = fullName.split(separator: " ").filter { !$0.isEmpty }
  1167. if parts.count >= 2 {
  1168. let a = parts[0].prefix(1)
  1169. let b = parts[1].prefix(1)
  1170. return "\(a)\(b)".uppercased()
  1171. }
  1172. if let first = parts.first { return String(first.prefix(2)).uppercased() }
  1173. return "CV"
  1174. }
  1175. private func headlineAccent() -> NSView {
  1176. let bar = NSView()
  1177. bar.translatesAutoresizingMaskIntoConstraints = false
  1178. bar.wantsLayer = true
  1179. switch template.accent {
  1180. case .none:
  1181. bar.heightAnchor.constraint(equalToConstant: 1).isActive = true
  1182. return bar
  1183. case .redUnderline:
  1184. bar.layer?.backgroundColor = CVResumeAppearance.accentColor(for: template).cgColor
  1185. bar.heightAnchor.constraint(equalToConstant: 2).isActive = true
  1186. bar.widthAnchor.constraint(equalToConstant: template.family == .minimal ? 140 : 168).isActive = true
  1187. return bar
  1188. case .redBar:
  1189. bar.layer?.backgroundColor = CVResumeAppearance.accentColor(for: template).cgColor
  1190. bar.heightAnchor.constraint(equalToConstant: 4).isActive = true
  1191. bar.widthAnchor.constraint(equalToConstant: 56).isActive = true
  1192. return bar
  1193. case .blueBar:
  1194. bar.layer?.backgroundColor = template.themeColor.cgColor
  1195. if template.headline == .centered {
  1196. bar.heightAnchor.constraint(equalToConstant: 2.5).isActive = true
  1197. bar.widthAnchor.constraint(equalToConstant: 148).isActive = true
  1198. } else {
  1199. bar.heightAnchor.constraint(equalToConstant: 4).isActive = true
  1200. bar.widthAnchor.constraint(equalToConstant: template.family == .executive ? 100 : 120).isActive = true
  1201. }
  1202. return bar
  1203. }
  1204. }
  1205. private func hairline() -> NSView {
  1206. let v = NSView()
  1207. v.translatesAutoresizingMaskIntoConstraints = false
  1208. v.wantsLayer = true
  1209. v.layer?.backgroundColor = style.rule.cgColor
  1210. let h: CGFloat = template.family == .executive ? 1.5 : 1
  1211. v.heightAnchor.constraint(equalToConstant: h).isActive = true
  1212. return v
  1213. }
  1214. private func sidebarColumn(tinted: Bool) -> NSView {
  1215. let box = NSStackView()
  1216. box.orientation = .vertical
  1217. box.spacing = 12
  1218. box.alignment = .leading
  1219. if tinted {
  1220. box.wantsLayer = true
  1221. let tint = (variant % 4 == 1)
  1222. ? template.themeColor.withAlphaComponent(0.08)
  1223. : CVResumeAppearance.colors().sidebarTint
  1224. box.layer?.backgroundColor = tint.cgColor
  1225. box.layer?.cornerRadius = variant % 3 == 0 ? 8 : 6
  1226. }
  1227. box.edgeInsets = NSEdgeInsets(top: tinted ? 14 : 0, left: tinted ? 14 : 0, bottom: tinted ? 14 : 0, right: tinted ? 14 : 0)
  1228. box.addArrangedSubview(sectionHeading("Contact"))
  1229. for line in contactLines() {
  1230. box.addArrangedSubview(label(line, font: style.contactFont, color: style.ink, maxLines: 0))
  1231. }
  1232. let skills = skillTokensFromProfile(max: 8)
  1233. if !skills.isEmpty {
  1234. box.addArrangedSubview(sectionHeading("Skills"))
  1235. if variant % 5 == 2 {
  1236. box.addArrangedSubview(skillTagRow(theme: template.themeColor, maxTags: 5))
  1237. } else {
  1238. for token in skills {
  1239. box.addArrangedSubview(label("· \(token)", font: style.contactFont, color: style.ink, maxLines: 0))
  1240. }
  1241. }
  1242. }
  1243. if variant % 7 == 3, let tools = nonEmpty(profile.certificates) {
  1244. box.addArrangedSubview(sectionHeading("Tools"))
  1245. box.addArrangedSubview(paragraph(tools, compact: true))
  1246. } else if let ancillary = combinedAncillaryText(), !ancillary.isEmpty {
  1247. box.addArrangedSubview(sectionHeading("Languages & more"))
  1248. box.addArrangedSubview(paragraph(ancillary, compact: true))
  1249. }
  1250. return box
  1251. }
  1252. private func bodyColumn(compact: Bool, experienceFirst: Bool = false) -> NSView {
  1253. let v = NSStackView()
  1254. v.orientation = .vertical
  1255. v.spacing = compact ? style.bodyBlockSpacing : style.bodyBlockSpacing + 2
  1256. v.alignment = .leading
  1257. let summaryTitle = sectionHeading(summarySectionTitle)
  1258. let summaryBody: NSView? = nonEmpty(profile.careerSummary).map { paragraph($0, compact: compact) }
  1259. let jobs = profile.workExperiences.filter { !$0.isEffectivelyEmpty }
  1260. let experienceHeading = sectionHeading("Experience")
  1261. var experienceBlocks: [NSView] = []
  1262. for job in jobs {
  1263. experienceBlocks.append(experienceBlock(job: job, compact: compact))
  1264. }
  1265. let schools = profile.educations.filter { !$0.isEffectivelyEmpty }
  1266. var educationBlocks: [NSView] = []
  1267. for edu in schools {
  1268. educationBlocks.append(educationBlock(edu: edu, compact: compact))
  1269. }
  1270. let appendSummary: () -> Void = { [self] in
  1271. if let body = summaryBody {
  1272. v.addArrangedSubview(summaryTitle)
  1273. v.addArrangedSubview(body)
  1274. }
  1275. }
  1276. let appendExperience: () -> Void = { [self] in
  1277. if !jobs.isEmpty {
  1278. v.addArrangedSubview(experienceHeading)
  1279. experienceBlocks.forEach { v.addArrangedSubview($0) }
  1280. }
  1281. }
  1282. let appendEducation: () -> Void = { [self] in
  1283. if !schools.isEmpty {
  1284. v.addArrangedSubview(sectionHeading("Education"))
  1285. educationBlocks.forEach { v.addArrangedSubview($0) }
  1286. }
  1287. }
  1288. if experienceFirst {
  1289. appendExperience()
  1290. appendSummary()
  1291. appendEducation()
  1292. } else {
  1293. appendSummary()
  1294. appendExperience()
  1295. appendEducation()
  1296. }
  1297. appendCertificatesInterestsReferrals(to: v, compact: compact)
  1298. return v
  1299. }
  1300. private func appendCertificatesInterestsReferrals(to v: NSStackView, compact: Bool) {
  1301. if let cert = nonEmpty(profile.certificates) {
  1302. v.addArrangedSubview(sectionHeading("Certificates"))
  1303. v.addArrangedSubview(paragraph(cert, compact: compact))
  1304. }
  1305. if let interests = nonEmpty(profile.interests) {
  1306. v.addArrangedSubview(sectionHeading("Interests"))
  1307. v.addArrangedSubview(paragraph(interests, compact: compact))
  1308. }
  1309. if let ref = nonEmpty(profile.referral) {
  1310. v.addArrangedSubview(sectionHeading("Referrals"))
  1311. v.addArrangedSubview(paragraph(ref, compact: compact))
  1312. }
  1313. }
  1314. private func skillTokensFromProfile(max: Int) -> [String] {
  1315. let raw = profile.languages.trimmingCharacters(in: .whitespacesAndNewlines)
  1316. if raw.isEmpty { return [] }
  1317. let parts = raw.split(whereSeparator: { $0 == "," || $0 == "·" || $0 == "|" || $0 == ";" })
  1318. .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
  1319. .filter { !$0.isEmpty }
  1320. if parts.count > 1 { return Array(parts.prefix(max)) }
  1321. return raw.split(separator: " ").map(String.init).filter { $0.count > 1 }.prefix(max).map { String($0) }
  1322. }
  1323. private func highlightsBodyText() -> String? {
  1324. if let t = nonEmpty(profile.interests) { return t }
  1325. if let r = nonEmpty(profile.referral) { return r }
  1326. let jobs = profile.workExperiences.filter { !$0.isEffectivelyEmpty }
  1327. if let first = jobs.first {
  1328. let bullets = Self.bulletChunks(from: first.description)
  1329. if let b = bullets.first { return b }
  1330. }
  1331. return nil
  1332. }
  1333. private func ancillaryBlock(title: String, body: String?) -> NSStackView? {
  1334. guard let body, !body.isEmpty else { return nil }
  1335. let s = NSStackView()
  1336. s.orientation = .vertical
  1337. s.spacing = 6
  1338. s.alignment = .leading
  1339. s.addArrangedSubview(sectionHeading(title))
  1340. s.addArrangedSubview(paragraph(body, compact: true))
  1341. return s
  1342. }
  1343. private func contactLines() -> [String] {
  1344. var lines: [String] = []
  1345. let p = profile.personal
  1346. if !p.email.isEmpty { lines.append(p.email) }
  1347. if !p.phone.isEmpty { lines.append(p.phone) }
  1348. if !p.address.isEmpty { lines.append(p.address) }
  1349. return lines.isEmpty ? ["—"] : lines
  1350. }
  1351. private func combinedAncillaryText() -> String? {
  1352. let chunks = [profile.languages, profile.interests].map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }.filter { !$0.isEmpty }
  1353. return chunks.isEmpty ? nil : chunks.joined(separator: "\n\n")
  1354. }
  1355. private func experienceBlock(job: WorkExperiencePayload, compact: Bool) -> NSView {
  1356. let v = NSStackView()
  1357. v.orientation = .vertical
  1358. v.spacing = template.family == .professional ? 4 : 6
  1359. v.alignment = .leading
  1360. if template.family == .professional {
  1361. let title = job.jobTitle.trimmingCharacters(in: .whitespacesAndNewlines)
  1362. let company = job.company.trimmingCharacters(in: .whitespacesAndNewlines)
  1363. let duration = job.duration.trimmingCharacters(in: .whitespacesAndNewlines)
  1364. if !title.isEmpty {
  1365. v.addArrangedSubview(label(title, font: style.expTitleFont, color: style.ink, maxLines: 0))
  1366. }
  1367. let metaParts = [company, duration].filter { !$0.isEmpty }
  1368. if !metaParts.isEmpty {
  1369. let metaJoined = metaParts.joined(separator: " · ")
  1370. v.addArrangedSubview(label(metaJoined, font: style.expMetaFont, color: template.themeColor, maxLines: 0))
  1371. } else if title.isEmpty {
  1372. let fallback = [job.jobTitle, job.company].filter { !$0.isEmpty }.joined(separator: " — ")
  1373. if !fallback.isEmpty {
  1374. v.addArrangedSubview(label(fallback, font: style.expTitleFont, color: style.ink, maxLines: 0))
  1375. }
  1376. }
  1377. } else {
  1378. let titleLine = [job.jobTitle, job.company].filter { !$0.isEmpty }.joined(separator: " — ")
  1379. let meta = job.duration.trimmingCharacters(in: .whitespacesAndNewlines)
  1380. if !titleLine.isEmpty {
  1381. v.addArrangedSubview(label(titleLine, font: style.expTitleFont, color: style.ink, maxLines: 0))
  1382. }
  1383. if !meta.isEmpty {
  1384. v.addArrangedSubview(label(meta, font: style.expMetaFont, color: template.themeColor, maxLines: 0))
  1385. }
  1386. }
  1387. for bullet in Self.bulletChunks(from: job.description) {
  1388. v.addArrangedSubview(bulletRow(bullet, compact: compact))
  1389. }
  1390. return v
  1391. }
  1392. private func educationBlock(edu: EducationPayload, compact: Bool) -> NSView {
  1393. let v = NSStackView()
  1394. v.orientation = .vertical
  1395. v.spacing = 4
  1396. v.alignment = .leading
  1397. let institution = edu.institution.trimmingCharacters(in: .whitespacesAndNewlines)
  1398. let degree = edu.degree.trimmingCharacters(in: .whitespacesAndNewlines)
  1399. let year = edu.year.trimmingCharacters(in: .whitespacesAndNewlines)
  1400. if template.family == .professional {
  1401. if !institution.isEmpty {
  1402. v.addArrangedSubview(label(institution, font: style.eduTitleFont, color: style.ink, maxLines: 0))
  1403. }
  1404. let subParts = [degree, year].filter { !$0.isEmpty }
  1405. if !subParts.isEmpty {
  1406. let sub = subParts.joined(separator: " · ")
  1407. v.addArrangedSubview(label(sub, font: style.eduMetaFont, color: style.muted, maxLines: 0))
  1408. }
  1409. } else {
  1410. let head = [edu.institution, edu.degree].filter { !$0.isEmpty }.joined(separator: " — ")
  1411. if !head.isEmpty {
  1412. v.addArrangedSubview(label(head, font: style.eduTitleFont, color: style.ink, maxLines: 0))
  1413. }
  1414. if !edu.year.isEmpty {
  1415. v.addArrangedSubview(label(edu.year, font: style.eduMetaFont, color: style.muted, maxLines: 0))
  1416. }
  1417. }
  1418. return v
  1419. }
  1420. private func bulletRow(_ text: String, compact: Bool) -> NSView {
  1421. let marker: String = template.family == .minimal ? "·" : "•"
  1422. let dot = NSTextField(labelWithString: marker)
  1423. dot.font = style.bulletMarkerFont
  1424. dot.textColor = style.bulletMarkerColor
  1425. dot.translatesAutoresizingMaskIntoConstraints = false
  1426. let bodyFont = compact ? style.bodyCompactFont : style.bulletBodyFont
  1427. let body = label(text, font: bodyFont, color: style.ink, maxLines: 0)
  1428. let row = NSStackView(views: [dot, body])
  1429. row.orientation = .horizontal
  1430. row.spacing = template.family == .creative ? 10 : 8
  1431. row.alignment = .top
  1432. dot.setContentHuggingPriority(.required, for: .horizontal)
  1433. return row
  1434. }
  1435. private func paragraph(_ text: String, compact: Bool) -> NSTextField {
  1436. let font = compact ? style.bodyCompactFont : style.bodyFont
  1437. return label(text, font: font, color: style.ink, maxLines: 0)
  1438. }
  1439. /// Gallery + ATS “Clear Path” style use “Profile”; other families keep the neutral résumé label.
  1440. private var summarySectionTitle: String {
  1441. template.family == .professional ? "Profile" : "Summary"
  1442. }
  1443. private func sectionHeading(_ raw: String) -> NSTextField {
  1444. let upper = raw.uppercased()
  1445. let s: String
  1446. switch template.sectionLabelStyle {
  1447. case .uppercase: s = upper
  1448. case .slashed: s = "// \(upper)"
  1449. case .bracketed: s = "[ \(upper) ]"
  1450. }
  1451. let t = NSTextField(labelWithString: s)
  1452. t.font = style.sectionFont
  1453. t.textColor = style.sectionInk
  1454. t.alignment = .left
  1455. return t
  1456. }
  1457. private func label(_ string: String, font: NSFont, color: NSColor, maxLines: Int) -> NSTextField {
  1458. let isWrapping = maxLines == 0
  1459. let t: NSTextField
  1460. if isWrapping {
  1461. t = NSTextField(wrappingLabelWithString: string)
  1462. t.maximumNumberOfLines = 0
  1463. } else {
  1464. t = NSTextField(labelWithString: string)
  1465. t.maximumNumberOfLines = maxLines
  1466. }
  1467. t.font = font
  1468. t.textColor = color
  1469. t.alignment = .left
  1470. return t
  1471. }
  1472. private func displayable(_ value: String, placeholder: String) -> String {
  1473. let t = value.trimmingCharacters(in: .whitespacesAndNewlines)
  1474. return t.isEmpty ? placeholder : t
  1475. }
  1476. private func nonEmpty(_ value: String) -> String? {
  1477. let t = value.trimmingCharacters(in: .whitespacesAndNewlines)
  1478. return t.isEmpty ? nil : t
  1479. }
  1480. private static func bulletChunks(from text: String) -> [String] {
  1481. let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
  1482. if trimmed.isEmpty { return [] }
  1483. let byNewline = trimmed.components(separatedBy: .newlines)
  1484. .map { $0.trimmingCharacters(in: .whitespaces) }
  1485. .filter { !$0.isEmpty }
  1486. if byNewline.count > 1 { return byNewline }
  1487. let byBullet = trimmed.split(separator: "•")
  1488. .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
  1489. .filter { !$0.isEmpty }
  1490. if byBullet.count > 1 { return byBullet.map { String($0) } }
  1491. return [trimmed]
  1492. }
  1493. }
  1494. // MARK: - Payload helpers
  1495. private extension WorkExperiencePayload {
  1496. var isEffectivelyEmpty: Bool {
  1497. [jobTitle, company, duration, description].allSatisfy { $0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }
  1498. }
  1499. }
  1500. private extension EducationPayload {
  1501. var isEffectivelyEmpty: Bool {
  1502. [degree, institution, year].allSatisfy { $0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }
  1503. }
  1504. }