%%
%% This is file `useclass.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% useclass.dtx  (with options: `package')
%% 
%%     Copyright (C) 2024 by HUANG Yuxi <useclass@hyxi.dev>
%% 
%%     This work may be distributed and/or modified under the
%%     conditions of the LaTeX Project Public License, either
%%     version 1.3c of this license or (at your option) any later
%%     version. This version of this license is in
%%        https://www.latex-project.org/lppl/lppl-1-3c.txt
%%     and the latest version of this license is in
%%        https://www.latex-project.org/lppl.txt
%%     and version 1.3c or later is part of all distributions of LaTeX
%%     version 2008 or later.
%% 
%%     This work has the LPPL maintenance status "maintained".
%% 
%%     The Current Maintainer of this work is HUANG Yuxi.
%% 

\NeedsTeXFormat{LaTeX2e}
\ProvidesExplPackage{useclass}
  {2024-03-06}{1.0}{Use Classes as Packages} %
\tl_const:Nn \c__useclass_cs_name_tl {__useclass_s_cs_}
\seq_new:N \g__useclass_tl_seq
\seq_new:N \g__useclass_dim_seq
\seq_new:N \g__useclass_cs_name_seq
\prop_new:N \l__useclass_class_prop
\seq_new:N \l__useclass_csname_seq
\tl_new:N \l__useclass_tmpa_tl
\tl_new:N \l__useclass_tmpb_tl
\dim_new:N \l__useclass_tmpa_dim
\cs_new_eq:NN \__useclass_tempa_cs:w ?
\cs_new_protected:Npn \__useclass_prop_get_prop:NnN #1 #2 #3
  {
    \prop_get:NnN #1 {#2} \l__useclass_tmpa_tl
    \exp_args:NNo \prop_set_from_keyval:Nn #3 \l__useclass_tmpa_tl
  }
\cs_new_protected:Npn \__useclass_prop_get_seq:NnN #1 #2 #3
  {
    \prop_get:NnN #1 {#2} \l__useclass_tmpa_tl
    \exp_args:NNo \seq_set_from_clist:Nn #3 \l__useclass_tmpa_tl
  }
\cs_new:Npn \__useclass_cs_swap:NN #1 #2
  {
    \cs_set_eq:NN \__useclass_tempa_cs:w #1
    \cs_set_eq:NN #1 #2
    \cs_set_eq:NN #2 \__useclass_tempa_cs:w
  }
\cs_new_protected:Npn \__useclass_save_tl:N #1
  {
    \__useclass_prop_get_seq:NnN #1 {tl} \l__useclass_csname_seq
    \seq_map_inline:Nn \l__useclass_csname_seq
      {
        \tl_set:Nx \l__useclass_tmpa_tl {\tl_use:c {##1}}
        \seq_gput_right:No \g__useclass_tl_seq {\l__useclass_tmpa_tl}
      }
  }
\cs_new_protected:Npn \__useclass_restore_tl:N #1
  {
    \__useclass_prop_get_seq:NnN #1 {tl} \l__useclass_csname_seq
    \seq_map_inline:Nn \l__useclass_csname_seq
      {
        \seq_gpop_left:NN \g__useclass_tl_seq \l__useclass_tmpa_tl
        \tl_set:cn {##1} {\l__useclass_tmpa_tl}
      }
  }
\cs_new_protected:Npn \__useclass_save_dim:N #1
  {
    \__useclass_prop_get_seq:NnN #1 {dim} \l__useclass_csname_seq
    \seq_map_inline:Nn \l__useclass_csname_seq
      {
        \tl_set:Nx \l__useclass_tmpa_tl {\dim_use:c {##1}}
        \seq_gput_right:No \g__useclass_dim_seq {\l__useclass_tmpa_tl}
      }
  }
\cs_new_protected:Npn \__useclass_restore_dim:N #1
  {
    \__useclass_prop_get_seq:NnN #1 {dim} \l__useclass_csname_seq
    \seq_map_inline:Nn \l__useclass_csname_seq
      {
        \seq_gpop_left:NN \g__useclass_dim_seq \l__useclass_tmpa_dim
        \dim_set:cn {##1} {\l__useclass_tmpa_dim}
      }
  }
\cs_new_protected:Npn \__useclass_save_cs:N #1
  {
    \__useclass_prop_get_seq:NnN #1 {cs} \l__useclass_csname_seq
    \seq_map_inline:Nn \l__useclass_csname_seq
      {
        \tl_concat:NNN \l__useclass_tmpa_tl \c__useclass_cs_name_tl {##1}
        \cs_set_eq:cc \l__useclass_tmpa_tl {##1}
        \seq_gput_right:No \g__useclass_cs_name_seq {\l__useclass_tmpa_tl}
      }
  }
\cs_new_protected:Npn \__useclass_restore_cs:N #1
  {
    \__useclass_prop_get_seq:NnN #1 {cs} \l__useclass_csname_seq
    \seq_map_inline:Nn \l__useclass_csname_seq
      {
        \seq_gpop_left:NN \g__useclass_cs_name_seq \l__useclass_tmpa_tl
        \cs_set_eq:cc {##1} \l__useclass_tmpa_tl
      }
  }
\cs_new:Npn \__useclass_LoadClass:n #1 {}
\cs_new_protected:Npn \__useclass_save_before:N #1
  {
    \__useclass_save_tl:N #1
    \__useclass_save_dim:N #1
    \__useclass_save_cs:N #1
  }
\cs_new_protected:Npn \__useclass_use_before:
  {
    \__useclass_cs_swap:NN \LoadClass \__useclass_LoadClass:n
  }
\cs_new_protected:Npn \__useclass_use_class:nn #1 #2
  {
    \@fileswithoptions\@clsextension[#1]{#2}
  }
\cs_new_protected:Npn \__useclass_use_after:
  {
    \__useclass_cs_swap:NN \LoadClass \__useclass_LoadClass:n
  }
\cs_new_protected:Npn \__useclass_restore_after:N #1
  {
    \__useclass_restore_cs:N #1
    \__useclass_restore_dim:N #1
    \__useclass_restore_tl:N #1
  }
\NewDocumentCommand {\useclass} { s O{} m }
  {
    \bool_if:NTF #1
      {
        \__useclass_prop_get_prop:NnN \c__useclass_classes_prop {#3} \l__useclass_class_prop
        \__useclass_save_before:N \l__useclass_class_prop
        \__useclass_use_before:
        \__useclass_use_class:nn {#2} {#3}
        \__useclass_use_after:
        \__useclass_restore_after:N \l__useclass_class_prop
      }
      {
        \__useclass_use_before:
        \__useclass_use_class:nn {#2} {#3}
        \__useclass_use_after:
      }
  }
\prop_const_from_keyval:Nn \c__useclass_classes_prop {
  l3doc = {
    tl = {
      partname,
    },
    dim = {
      textwidth,
      marginparwidth,
      oddsidemargin,
      evensidemargin,
      parindent,
      itemindent,
      parskip,
    },
    cs = {
      list,
      l@section,
      l@subsection,
    },
  },
}
%% 
%%     This work consists of the files useclass.dtx
%%     and the derived files useclass.sty and useclass.ins.
%% 
%%
%% End of file `useclass.sty'.
