CVProfileDocumentView.swift 72 KB

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