\NeedsTeXFormat{LaTeX2e}
\ProvidesExplPackage{PrimeTeX/packages/Fonts}{2025-09-18}{1.0}{
	Font definitions.
}

% Loading math fonts takes a long time, so skip it in draft mode.
\bool_if:NF \g_draft_bool {
	\RequirePackage{notomath}
}

\NewDocumentCommand{\fontpath}{}{./PrimeTeX/fonts}

% Define fallback fonts for each main font.
\directlua {
	luaotfload.add_fallback(
		"RobotoSerif", {
			"NotoSerif:mode=harf;",
			"NotoSansSymbols:mode=harf;",
			"NotoSansSymbols2:mode=harf;",
			"NotoEmoji:mode=harf;",
		}
	)

	luaotfload.add_fallback(
		"Roboto", {
			"NotoSans-Medium:mode=harf;",
			"NotoSansSymbols-SemiBold:mode=harf;",
			"NotoSansSymbols2:mode=harf;",
			"NotoEmoji:mode=harf;",
		}
	)

	luaotfload.add_fallback(
		"RobotoMono", {
			"NotoSansMono-Medium:mode=harf;",
			"NotoSansSymbols-SemiBold:mode=harf;",
			"NotoSansSymbols2:mode=harf;",
			"NotoEmoji:mode=harf;",
		}
	)

	luaotfload.add_fallback(
		"RobotoSlab", {
			"NotoSerif-SemiBold:mode=harf;",
			"NotoSansSymbols-SemiBold:mode=harf;",
			"NotoSansSymbols2:mode=harf;",
			"NotoEmoji-SemiBold:mode=harf;",
		}
	)
}

% Main font: Roboto Serif (Light)
\setmainfont{RobotoSerif}[
	Extension		= .ttf,
	UprightFont		= *-Light,
	BoldFont		= *-SemiBold,
	ItalicFont		= *-LightItalic,
	BoldItalicFont	= *-SemiBoldItalic,
	SlantFont		= RobotoSlab-SemiBold,
	BoldSlantFont	= RobotoSlab-Black,
	RawFeature		= {fallback=RobotoSerif},
]
% \setmainfont{Roboto~Serif}[
% 	Weight	= 300,
% 	Width	= 85,
%  	RawFeature		= {fallback=RobotoSerif},
% ]

% % Sans serif font: Roboto (Medium).
\setsansfont{Roboto}[
	Extension		= .ttf,
	UprightFont		= *-Medium,
	BoldFont		= *-Bold,
	ItalicFont		= *-MediumItalic,
	BoldItalicFont	= *-BoldItalic,
	RawFeature		= {fallback=Roboto},
]

% Monospace font: Roboto Mono
\setmonofont{RobotoMono}[
	Extension		= .ttf,
	UprightFont		= *-Medium,
	BoldFont		= *-Bold,
	ItalicFont		= *-MediumItalic,
	BoldItalicFont	= *-BoldItalic,
	RawFeature		= {fallback=RobotoMono},
]

% Headings & Titles font: Roboto Slab (Semibold).
\newfontfamily{\sbfamily}{RobotoSlab}[
	Extension		= .ttf,
	UprightFont		= *-SemiBold,
	BoldFont		= *-Black,
	% Roboto Slab doesn't have any italic form, so use
	% the Roboto Serif version.
	ItalicFont		= RobotoSerif-SemiBoldItalic,
	BoldItalicFont	= RobotoSerif-ExtraBoldItalic,
	RawFeature		= {fallback=RobotoSlab},
]

% \setmathrm{RobotoSerif}

\NewDocumentCommand{\serif}{+m}{{\rmfamily{}#1}}
\NewDocumentCommand{\sans}{+m}{{\sffamily{}#1}}
\NewDocumentCommand{\mono}{+m}{{\ttfamily{}#1}}
\NewDocumentCommand{\slab}{+m}{{\sbfamily{}#1}}
\NewDocumentCommand{\code}{+m}{\mono{\small{}#1}}

%------------------------------- Symbol Commands -------------------------------

% Line-breaking zero-width space.
\NewDocumentCommand{\zws}{}{\hspace{0pt}}

% Line-breaking dot.
\NewDocumentCommand{\bdot}{}{.\zws}

% Bullets for itemize lists.
\renewcommand{\labelitemi}{▪}
\renewcommand{\labelitemii}{⬩}
\renewcommand{\labelitemiii}{‣}
\renewcommand{\labelitemiv}{•}

%--------------------------- MenuKeys Configuration ----------------------------

\newmenucolortheme{autoModeColor}{named}{pageColor}{textColor}{textColor}[pageColor][textColor][textColor]

\changemenucolortheme{hyphenatepaths}{autoModeColor}
\changemenucolortheme{shadowedroundedkeys}{autoModeColor}
\changemenucolortheme{angularmenus}{autoModeColor}

\cs_new:Nn \__MenuKeys_path_style: {
	\sffamily\color{\usemenucolor{txt}}\CurrentMenuElement
}

\newmenustyle{mypaths}[
	\group_begin:
	\sffamily
	\color{\usemenucolor{txt}}
]{}[⏵\zws]{}{}{}[\group_end:]{autoModeColor}

% \changemenuelement*{hyphenatepaths}{first}{\__MenuKeys_path_style:}
% \changemenuelement*{hyphenatepaths}{middle}{\__MenuKeys_path_style:}
% \changemenuelement*{hyphenatepaths}{last}{\__MenuKeys_path_style:}
% \changemenuelement*{hyphenatepaths}{single}{\__MenuKeys_path_style:}

\renewmenumacro{\directory}[/]{mypaths}
\renewmenumacro{\keys}[+]{shadowedroundedkeys}
\renewmenumacro{\menu}[>]{angularmenus}

\RenewDocumentCommand{\ctrlname}{}{$\wedge$}

\NewDocumentCommand{\ControlString}{}{Ctrl}
\NewDocumentCommand{\EnterString}{}{Enter\,\return}
\NewDocumentCommand{\ShiftString}{}{Shift\,\shift}
\NewDocumentCommand{\AltString}{}{Alt\,\altmac}
\NewDocumentCommand{\TabString}{}{Tab\,\tab}

\NewDocumentCommand{\ControlKey}{}{\keys{\ControlString}}
\NewDocumentCommand{\EnterKey}{}{\keys{\EnterString}}
\NewDocumentCommand{\ShiftKey}{}{\keys{\ShiftString}}
\NewDocumentCommand{\AltKey}{}{\keys{\AltString}}
\NewDocumentCommand{\TabKey}{}{\keys{\TabString}}

% Suppress warning about obsolete font encodings because we're using Unicode.
\@tw@hyphenatepaths@warnigfalse % [sic]

%------------------------- Custom Directory Formatting -------------------------

% The MenuKeys approach is too complicated for directory formatting. This is a
% simpler method.

\tl_new:N \l_@@_dir_tl

\keys_define:nn {Dir} {
	font		.tl_set:N	= \l_Dir_font_tl,
	font		.initial:n	= {\sffamily},

	separator	.tl_set:N	= \l_Dir_separator_tl,
	separator	.initial:n	= {\thinspace⏵\hspace{0.17em}},
}

\NewDocumentCommand{\Dir}{O{} m}{
	\group_begin:
		\keys_set:nn {Dir} {#1}

		\str_set:Nn \l_@@_dir_tl {#2}
		\tl_replace_all:Nnn \l_@@_dir_tl {/} {\l_Dir_separator_tl}

		\tl_use:N \l_Dir_font_tl
		\tl_use:N \l_@@_dir_tl
	\group_end:
}