\NeedsTeXFormat{LaTeX2e}
\ProvidesExplPackage{PrimeTeX/packages/Graphics}{2025-09-03}{1.0}{
	Custom non-floating Graphics commands.
}

\RequirePackage{PrimeTeX/packages/Layout}

\RequirePackage{calc}

\RequirePackage{wrapstuff}

\dim_const:Nn \c_Graphics_icon_dim {0.25in}

\NewDocumentCommand{\IconSize}{}{\c_Graphics_icon_dim}

\keys_define:nn{InlineGraphic}{
	height	.dim_set:N	= \l_InlineGraphic_height_dim,
	height	.initial:n	= {12pt},
%	height	.default:n	= {12pt},

	offset	.dim_set:N	= \l_InlineGraphic_offset_dim,
	offset	.initial:n	= {-2pt},
%	offset	.default:n	= {-2pt},
}

\NewDocumentCommand{\InlineGraphic}{
	% Key=value options.
	O{}
	% Graphic file.
	m
}{%
	\keys_set:nn{InlineGraphic}{#1}
	\raisebox{\l_InlineGraphic_offset_dim}{
		\includegraphics[%
			keepaspectratio,height=12pt%\l_InlineGraphic_height_dim%
		]{#2}
	}%
}

\dim_const:Nn \c_ig_width_dim {0.5in}

% Shorthand command for \includegraphics.
\NewDocumentCommand{\ig}{O{width=\c_ig_width_dim} m}{%
	\includegraphics[keepaspectratio,#1]{#2}%
}

\str_const:Nn \c_WrapFig_placement_str {o}
\dim_const:Nn \c_WrapFig_hoffset_dim {\marparwidth}

\keys_define:nn {WrapFig} {
	placement	.choices:nn	= {l,r,c,i,o}{
		\str_set:Ne \l_WrapFig_placement_str {\l_keys_choice_tl}
	},
	placement	.initial:e	= {\c_WrapFig_placement_str},

	hoffset		.dim_set:N	= \l_WrapFig_hoffset_dim,
	hoffset		.initial:e	= {\c_WrapFig_hoffset_dim},
}

\NewDocumentCommand{\WrapFig}{
	% #1: Key-value options
	O{}
	% #2: graphic_file
	m
	% #3: Options passed to \includegraphics
	O{}
	% #4: label
	>{\TrimSpaces}m
	% #5: caption
	m
}{ \group_begin:
	\keys_set:nn {WrapFig} {#1}
	\expanded{\noexpand\begin{wrapstuff}[
		\l_WrapFig_placement_str,
		hoffset	= \l_WrapFig_hoffset_dim,
	]}
		\begin{MyCaption}{fig:#4}{#5}
			\includegraphics[%
				keepaspectratio,%
				#3%
			]{#2}%
		\end{MyCaption}
	\end{wrapstuff}
\group_end: }