%
% ***************** THE PASSOPT PACKAGE *****************
%
% Copyright (C) 2024 by Qu Yi <toquyi@163.com>
%
% This work may be distributed and/or modified under the
% conditions of the CC-BY 4.0 License.
% The latest version of this license is in
%   https://creativecommons.org/licenses/by/4.0/legalcode
\NeedsTeXFormat{LaTeX2e}[2021/11/15]
\ProvidesExplPackage{passopt}{2024/07/11}{1.00b}
  {Passing options to packages or classes}

\cs_generate_variant:Nn \tl_if_blank:nF { v }
\cs_new:Npn \po_save_option_list:n #1 { #1 }
\cs_new:Npn \po_add_before_hook:nnn #1#2
  { \AddToHook{#1/#2/before}[passopt] }
\NewDocumentCommand{\SetOptionsToPackage}{smm}
  {
    \po_add_before_hook:nnn { package } {#3}
      {
        \cs_gset:cpx { @raw@opt@#3.sty }
          {
            \IfBooleanF{#1}
              {
                \tl_if_blank:vF { opt@#3.sty }
                  { \use:c { opt@#3.sty }, }
              }
            \po_save_option_list:n {#2}
          }
      }
  }
\NewDocumentCommand{\SetOptionsToClass}{smm}
  {
    \po_add_before_hook:nnn { class } {#3}
      {
        \cs_gset:cpx { @raw@opt@#3.cls }
          {
            \IfBooleanF{#1}
              {
                \tl_if_blank:vF { opt@#3.cls }
                  { \use:c { opt@#3.cls }, }
              }
            \po_save_option_list:n {#2}
          }
      }
  }
\cs_new_protected:Npn \ClearPackageOptions #1
  {
    \po_add_before_hook:nnn { package } {#1}
      { \tl_clear:c { opt@#1.sty } }
  }
\cs_new_protected:Npn \ClearClassOptions #1
  {
    \po_add_before_hook:nnn { class } {#1}
      { \tl_clear:c { opt@#1.cls } }
  }
\endinput
%
% End of file `passopt.sty'.