%%
%% This is file `latex-lab-testphase-block.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% latex-lab-block.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright 2021-2023 LaTeX Project
%% 
%% This file was generated from file(s) of the  `LaTeX-lab Bundle'.
%% ------------------------------------------------------------------------------------
%% 
%% It 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.
%% The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2008 or later.
%% 
%% This file may only be distributed together with a copy of the LaTeX
%% `LaTeX-lab Bundle'. You may however distribute the `LaTeX-lab Bundle'
%% without such generated files.
%% 
%% The newest sources can be found below
%% 
%%    https://github.com/latex3/latex2e/required/latex-lab
%% 
%% where one can also log issues in case there are any.
%% 
%% 
%% File: latex-lab-block.dtx (C) Copyright 2021-2024 LaTeX Project
\def\ltlabblockdate{2024-02-12}
\def\ltlabblockversion{0.8l}
\ProvidesPackage {latex-lab-testphase-block}
                 [\ltlabblockdate\space v\ltlabblockversion\space
                            blockenv implementation]
\RequirePackage{latex-lab-kernel-changes}
\ExplSyntaxOn
\tl_new:N \l__block_item_align_tl
\tl_new:N\l__block_legacy_env_params_tl
\def\@doendpe{\@endpetrue
  \def\par
    {
      \@restorepar
      \clubpenalty\@clubpenalty
      \__kernel_displayblock_doendpe:
      \@endpefalse
      \everypar{}
      \par
    }
  \everypar{{\setbox\z@\lastbox}
            \everypar{}
            \@endpefalse
  }
}
\cs_new_eq:NN \__kernel_displayblock_doendpe: \prg_do_nothing:
\def\@endpetrue {\global\let\if@endpe\iftrue}
\def\@endpefalse{\global\let\if@endpe\iffalse}
\NewTemplateType{blockenv}{1}
\NewTemplateType{block}{1}
\NewTemplateType{para}{1}
\NewTemplateType{list}{1}
\NewTemplateType{item}{1}
\DeclareTemplateInterface{blockenv}{display}{1}
{
  env-name       : tokenlist ,
  tag-name       : tokenlist ,
  tag-class      : tokenlist ,
  tagging-recipe : tokenlist = standard,
  level-increase : boolean = true ,
  setup-code     : tokenlist ,
  block-instance : tokenlist = displayblock ,
  para-instance  : tokenlist ,
  inner-level-counter : tokenlist,
  max-inner-levels    : tokenlist = 4,
  inner-instance-type : tokenlist = list ,
  inner-instance      : tokenlist ,
  para-flattened : boolean = false ,
  final-code     : tokenlist = \ignorespaces ,
}
\DeclareTemplateInterface{block}{display}{1}
{
  heading        : tokenlist = ,                               %??
  beginsep       : skip = \topsep ,
  begin-par-skip : skip = \partopsep ,
  par-skip       : skip = \parsep ,
  end-skip       : skip = \KeyValue{beginsep} ,                % conflict with name below
  end-par-skip   : skip = \KeyValue{begin-par-skip} ,
  beginpenalty   : integer = \UseName{@beginparpenalty} ,
  endpenalty     : integer = \UseName{@endparpenalty} ,
  leftmargin     : length = \leftmargin ,
  rightmargin    : length = \rightmargin ,
  parindent      : length = \listparindent ,
}
\DeclareTemplateInterface{para}{std}{1}
{
  indent-width          : length = \parindent ,
  start-skip            : skip = 0pt  ,
  left-skip             : skip = 0pt ,
  right-skip            : skip = 0pt ,
  end-skip              : skip = \@flushglue ,
  fixed-word-spaces     : boolean = false ,
  final-hyphen-demerits : integer = 5000 ,
  cr-cmd                : tokenlist = \@normalcr ,
  para-class            : tokenlist = justify ,
}
\DeclareTemplateInterface{list}{std}{1}     % optional
{
  counter         : tokenlist = ,
  item-label      : tokenlist = ,
  start           : integer = 1 ,
  resume          : boolean = false ,
  item-instance   : instance{item} = basic ,
  item-skip       : skip = \itemsep ,
  item-penalty    : integer = \UseName{@itempenalty} ,
  item-indent     : length = 0pt ,         % was \itemindent
  label-width     : length = \labelwidth ,
  label-sep       : length = \labelsep ,
  legacy-support   : boolean = false ,
}
\DeclareTemplateInterface{item}{std}{1}
  {
    counter-label : function{1} = \arabic{#1} ,
    counter-ref   : function{1} = \KeyValue{counter-label} ,
    label-ref     : function{1} = #1 ,
    label-autoref : function{1} = item~#1 ,
    label-format  : function{1} = #1 ,
    label-strut   : boolean = false ,
    label-align   : choice {left,center,right,parleft} = right ,
    label-boxed   : boolean = true ,
    next-line     : boolean = false ,
    text-font     : tokenlist ,
    compatibility : boolean = true ,
  }
\cs_new_protected:Npn \__block_skip_set_to_last:N #1 {
  \skip_set:Nn #1 { \tex_lastskip:D }
}
\cs_new_eq:NN \__block_skip_remove_last: \tex_unskip:D
\cs_generate_variant:Nn \tl_if_novalue:nTF { o }
\bool_new:N \g__block_debug_bool
\cs_new_eq:NN \__block_debug:n \use_none:n
\cs_new_eq:NN \__block_debug_typeout:n \use_none:n
\cs_new_protected:Npn \block_debug_on:
  {
    \bool_gset_true:N \g__block_debug_bool
    \__block_debug_gset:
  }
\cs_new_protected:Npn \block_debug_off:
  {
    \bool_gset_false:N \g__block_debug_bool
    \__block_debug_gset:
  }
\cs_new_protected:Npn \__block_debug_gset:
  {
    \cs_gset_protected:Npx \__block_debug:n ##1
      { \bool_if:NT \g__block_debug_bool {##1} }
    \cs_gset_protected:Npx \__block_debug_typeout:n ##1
      { \bool_if:NT \g__block_debug_bool { \typeout{==>~ ##1} } }
  }
\cs_new_protected:Npn \DebugBlocksOn  { \block_debug_on:  }
\cs_new_protected:Npn \DebugBlocksOff { \block_debug_off: }
\DebugBlocksOff
\NewDocumentEnvironment{displayblock}{ !O{} }
  { \UseInstance{blockenv}{displayblock} {#1} }
  { \endblockenv }
\NewDocumentEnvironment{displayblockflattened}{ !O{} }
  { \UseInstance{blockenv}{displayblockflattened} {#1} }
  { \endblockenv }
\AddToHook{begindocument/before}{
  \RenewDocumentEnvironment{center} { !O{} }
  { \UseInstance{blockenv}{center}{#1} }
  { \endblockenv }
  \RenewDocumentEnvironment{flushright} { !O{} }
  { \UseInstance{blockenv}{flushright}{#1} }
  { \endblockenv }
  \RenewDocumentEnvironment{flushleft} { !O{} }
  { \UseInstance{blockenv}{flushleft}{#1} }
  { \endblockenv }
}
\AddToHook{begindocument/before}{
  \RenewDocumentEnvironment{quote}{ !O{} }
    { \UseInstance{blockenv}{quote} {#1} }
    { \endblockenv }
  \RenewDocumentEnvironment{quotation}{ !O{} }
    { \UseInstance{blockenv}{quotation} {#1} }
    { \endblockenv }
}
\AddToHook{begindocument/before}{
  \RenewDocumentEnvironment{verbatim}{ !O{} }
    { \UseInstance{blockenv}{verbatim} {#1}
      \@setupverbinvisiblespace\frenchspacing\@vobeyspaces
      \@xverbatim
    }
    { \endblockenv }
  \RenewDocumentEnvironment{verbatim*}{ !O{} }
    { \UseInstance{blockenv}{verbatim} {#1}
      \@setupverbvisiblespace\frenchspacing\@vobeyspaces
      \@sxverbatim
    }
    { \endblockenv }
}
\def\legacyverbatimsetup{%
  \language\l@nohyphenation
  \@tempswafalse
  \def\par{%
    \if@tempswa
      \leavevmode \null {\@@par}\penalty\interlinepenalty
    \else
      \@tempswatrue
      \ifhmode{\@@par}\penalty\interlinepenalty\fi
    \fi}%
  \let\do\@makeother \dospecials
  \obeylines \verbatim@font \@noligs
  \everypar \expandafter{\the\everypar \unpenalty}%
  \tl_set:Nn \l__tag_para_main_tag_tl {codeline}
  \tagtool{paratag=Code}%   oder faster: \tl_set:Nn\l__tag_para_tag_tl{Code}
}
\newcommand\@setupverbinvisiblespace{}
\tag_if_active:T {
  \bool_if:NF\g__tag_mode_lua_bool
   {
     \renewcommand\@setupverbinvisiblespace{\def\@xobeysp{\nobreakspace\pdffakespace}}
   }
}
\AddToHook{begindocument/before}{
  \RenewDocumentEnvironment{itemize}{!O{}}
    { \UseInstance{blockenv}{itemize} {#1} }
    { \endblockenv }
  \RenewDocumentEnvironment{enumerate}{!O{}}
    { \UseInstance{blockenv}{enumerate} {#1} }
    { \endblockenv }
  \RenewDocumentEnvironment{description}{!O{}}
    { \UseInstance{blockenv}{description} {#1} }
    { \endblockenv }
}
\AddToHook{begindocument/before}{
  \RenewDocumentEnvironment{verse}{ !O{} }
    {
      \let\\\@centercr
      \UseInstance{blockenv}{list}
        {
          item-indent=-1.5em,
          parindent=-1.5em,
          item-skip=0pt,
          rightmargin=\leftmargin,
          leftmargin=\leftmargin+1.5em,
          #1
         }
      \item\relax
    }
    { \endblockenv }
  }
\AddToHook{begindocument/before}{
  \RenewDocumentEnvironment{list}{O{} m m }
    {
      \tl_set:Nn \@itemlabel {#2}
      \tl_set:Nn \l__block_legacy_env_params_tl {#3}
      \UseInstance{blockenv}{list} {#1}
    }
    { \endblockenv }
}
\tl_new:N \l__block_env_params_tl
\cs_new:Npn \legacylistsetupcode {
    \dim_zero:N \listparindent
    \dim_zero:N \rightmargin
    \dim_zero:N \itemindent
    \tl_set:Nn \@listctr {}
    \legacy_if_set_false:n { @nmbrlist } % needed if lists are nested
   \let\makelabel\@mklab % TODO: customize
   \l__block_legacy_env_params_tl
    \legacy_if:nTF { @nmbrlist }
      { \tl_set:Nn \l__tag_L_attr_class_tl {enumerate} }   % numbered list
      { \tl_if_empty:NTF \@itemlabel
          { \tl_set:Nn \l__tag_L_attr_class_tl {list}    } % no label
          { \tl_set:Nn \l__tag_L_attr_class_tl {itemize} } % unnumbered, unordered
      }
}
\AddToHook{begindocument/before}{
  \RenewDocumentEnvironment{trivlist}{ !O{} }
                           { \list[#1]{}
                             {
                               \dim_zero:N \leftmargin
                               \dim_zero:N \labelwidth
                               \cs_set_eq:NN \makelabel \use:n
                             }
                           }
    { \endblockenv }
}
\RenewDocumentCommand \newtheorem { m O{#1} m o }
{
  \expandafter\@ifdefinable\csname #1\endcsname
    {
      \str_if_eq:nnTF{#1}{#2}
         {
           \@definecounter {#2}
           \IfNoValueTF {#4}
             {  % @ynthm
               \tl_gset:ce { the #2 }
                  {
                    \@thmcounter{#2}
                  }
             }
             {  % @xnthm
               \@newctr{#1}[#4]
               \tl_gset:ce { the #2 }
                  {
                    \expandafter\noexpand\csname the#4\endcsname
                    \@thmcountersep
                    \@thmcounter{#2}
                  }
             }
         }
         {  % @othm
           \@ifundefined{c@#2}
              { \@nocounterr{#2} }
              {
                \tl_gset:cn { the #1 }
                   { \UseName { the #2 } }
              }
         }
      \global\@namedef{#1}   { \@thm{#2}{#3} }
      \global\@namedef{end#1}{ \@endtheorem  }
    }
}
\tl_new:N \l__block_thm_current_counter_tl
\def\@thm#1#2{%
  \@kernel@refstepcounter{#1}
  \tl_set:Nn \l__block_thm_current_counter_tl{#1}
  \@ifnextchar[{\@ythm{#1}{#2}}{\@xthm{#1}{#2}}}
\def\hyper@nopatch@thm{}
\def\@begintheorem#1#2{
  \UseInstance{blockenv}{theorem}{}
  \tagpdfparaOff
  \mode_leave_vertical:
  \MakeLinkTarget{\l__block_thm_current_counter_tl}
  \tag_struct_begin:n{tag=Caption}
   \group_begin:
   \bfseries
   \tag_mc_begin:n {}
     #1\
   \tag_mc_end:
    \tag_struct_begin:n{tag=Lbl}
      \tag_mc_begin:n {}
          #2
      \tag_mc_end:
    \tag_struct_end:
    \group_end:
  \tag_struct_end:
  \tagpdfparaOn
  \__block_start_para_structure_unconditionally:n { \PARALABEL }
  \itshape
  \hskip\labelsep
  \ignorespaces
}
\def\@opargbegintheorem#1#2#3{
  \UseInstance{blockenv}{theorem}{}
  \tagpdfparaOff
  \mode_leave_vertical:
  \MakeLinkTarget{\l__block_thm_current_counter_tl}
  \tag_struct_begin:n{tag=Caption}
   \group_begin:
   \bfseries
   \tag_mc_begin:n {}
      #1\
   \tag_mc_end:
   \tag_struct_begin:n{tag=Lbl}
     \tag_mc_begin:n {}
       #2
     \tag_mc_end:
   \tag_struct_end:
     \tag_mc_begin:n {}
      \ (#3)
     \tag_mc_end:
   \group_end:
  \tag_struct_end:
  \tagpdfparaOn
  \__block_start_para_structure_unconditionally:n { \PARALABEL }
  \itshape
  \hskip\labelsep
  \ignorespaces
}
\def\@endtheorem{\endblockenv}
\cs_new:Npn \g_block_nesting_depth_int { \@listdepth }  % a fake int
                                                        % for now
\DeclareTemplateCode{blockenv}{display}{1}
{
  env-name       = \l__block_env_name_tl ,
  tag-name       = \l__block_tag_name_tl ,
  tag-class      = \l__block_tag_class_tl ,
  tagging-recipe = \l__block_tagging_recipe_tl ,
  level-increase = \l__block_level_incr_bool ,
  setup-code     = \l__block_setup_code_tl ,
  block-instance = \l__block_block_instance_tl ,
  para-instance  = \l__block_para_instance_tl ,
  inner-level-counter = \l__block_inner_level_counter_tl ,
  max-inner-levels    = \l__block_max_inner_levels_tl ,
  inner-instance-type = \l__block_inner_instance_type_tl ,
  inner-instance      = \l__block_inner_instance_tl ,
  para-flattened = \l__tag_para_flattened_bool ,
  final-code     = \l__block_final_code_tl ,
}
{
  \__block_debug_typeout:n{\l__block_env_name_tl -env-start}
  \tl_if_empty:nF {#1} { \SetTemplateKeys{blockenv}{display}{#1} }
  %    \begin{macrocode}
  \int_compare:nNnTF \l__block_flattened_level_int > 0
      {
        \int_incr:N \l__block_flattened_level_int
      }
      {
        \bool_if:NT \l__tag_para_flattened_bool
             {
               \int_incr:N \l__block_flattened_level_int
             }
      }
  \tl_if_empty:NF \l__block_inner_level_counter_tl
     {
       \int_compare:nNnTF  \l__block_inner_level_counter_tl >
                           { \l__block_max_inner_levels_tl - 1 }
           { \@toodeep }
           { \int_incr:N \l__block_inner_level_counter_tl }  % not clean "o"?
     }
  \bool_if:NT \l__block_level_incr_bool
     {
       \int_compare:nNnTF  \g_block_nesting_depth_int >
                           { \c@maxblocklevels - 1 }
           { \@toodeep }
           {
             \int_gincr:N \g_block_nesting_depth_int
             \use:c { @list \int_to_roman:n { \g_block_nesting_depth_int } }
           }
     }
  \tag_if_active:T { \use:c { __block_recipe_ \l__block_tagging_recipe_tl : } }
  \l__block_setup_code_tl
  \__block_debug_typeout:n{use~ instance:~
           \l__block_block_instance_tl - \int_use:N \g_block_nesting_depth_int }
  \UseInstance{block}
              { \l__block_block_instance_tl - \int_use:N
                \g_block_nesting_depth_int }
              {#1}
  \tl_if_empty:NF \l__block_para_instance_tl
    {
      \__block_debug_typeout:n{use~ para~ instance:~ \l__block_para_instance_tl }
      \UseInstance{para}{ \l__block_para_instance_tl } {}
    }
  \tl_if_empty:NF \l__block_inner_instance_tl
    {
      \__block_debug_typeout:n{use~ instance:~ \l__block_inner_instance_tl
               \tl_if_empty:NF \l__block_inner_level_counter_tl
                       { - \int_use:N \l__block_inner_level_counter_tl }}
      \UseInstance{ \l__block_inner_instance_type_tl }
                  { \l__block_inner_instance_tl
                    \tl_if_empty:NF \l__block_inner_level_counter_tl
                       { - \int_use:N \l__block_inner_level_counter_tl }  % not clean
                                                                % use "o"?
                  }
                  {#1}
    }
  \l__block_final_code_tl
}
\int_new:N \l__block_flattened_level_int
\newcounter{maxblocklevels}
\setcounter{maxblocklevels}{6}
\cs_new:Npn \endblockenv {
  \__block_debug_typeout:n{blockenv~ common~ ending \on@line}
  \bool_if:NT \l__block_level_incr_bool
    { \int_gdecr:N \g_block_nesting_depth_int }
  \legacy_if:nT { @inlabel }
    {
      \mode_leave_vertical:
      \legacy_if_gset_false:n { @inlabel }
    }
  \legacy_if:nT { @newlist }
    {
      \@noitemerr
      \legacy_if_gset_false:n { @newlist }
    }
  \mode_if_horizontal:TF
       { \__block_skip_remove_last: \__block_skip_remove_last: \par }
       { \@inmatherr{\end{\@currenvir}} }
  \__kernel_displayblock_end:
  \legacy_if:nF { @noparlist }
    {
      \__block_skip_set_to_last:N \l_tmpa_skip
      \dim_compare:nNnT \l_tmpa_skip > \c_zero_dim
        {
          \skip_vertical:n { - \l_tmpa_skip }
          \skip_vertical:n { \l_tmpa_skip + \parskip - \@outerparskip }
        }
      \addpenalty \@endparpenalty
      \addvspace \l__block_topsepadd_skip
    }
  \socket_use:n {tagsupport/block-endpe}
}
\cs_new:Npn \__kernel_displayblock_end: {
  \__block_debug_typeout:n{\detokenize{__kernel_displayblock_end:}}
}
\socket_new:nn      {tagsupport/block-endpe}{0}
\socket_new_plug:nnn{tagsupport/block-endpe}{on}
                    { \legacy_if_gset_true:n  { @endpe } }
\socket_new_plug:nnn{tagsupport/block-endpe}{off}
                    { \legacy_if_gset_false:n { @endpe } }
\socket_assign_plug:nn{tagsupport/block-endpe}{on}
\DeclareTemplateCode{para}{std}{1}
{
  indent-width      = \parindent ,
  start-skip        = \l__par_start_skip ,              % name??
  left-skip         = \leftskip  ,
  right-skip        = \rightskip  ,
  end-skip          = \parfillskip ,
  fixed-word-spaces = \l__par_fixed_word_spaces_bool ,  % name??
  final-hyphen-demerits = \finalhyphendemerits ,
  cr-cmd                = \\ ,
  para-class            = \l__tag_para_attr_class_tl ,
}
{
  \tl_if_empty:nF {#1} { \SetTemplateKeys{para}{std}{#1} }
  \skip_set:Nn \@rightskip \rightskip
}
\DeclareTemplateCode{block}{display}{1}
{
  heading         = \l__block_heading_tl ,
  beginsep        = \topsep ,
  begin-par-skip  = \partopsep ,
  par-skip        = \parsep ,
  end-skip        = \l__block_botsep_skip ,
  end-par-skip    = \l__block_parbotsep_skip ,
  beginpenalty    = \@beginparpenalty ,
  endpenalty      = \@endparpenalty ,
  rightmargin     = \rightmargin ,
  leftmargin      = \leftmargin ,
  parindent       = \listparindent ,
}
{
  \tl_if_empty:nF {#1} { \SetTemplateKeys{block}{display}{#1} }
    \tl_if_blank:oF \l__block_heading_tl
      { \mode_leave_vertical: \textbf{\l__block_heading_tl} } % TODO customize
    \legacy_if:nT { @noskipsec } { \mode_leave_vertical: }
    \skip_set:Nn \l__block_topsepadd_skip { \topsep }
    \mode_if_vertical:TF
      {
        \skip_add:Nn \l__block_topsepadd_skip { \partopsep }
        \__kernel_displayblock_beginpar_vmode:
      }
      {
        \__block_skip_remove_last: \__block_skip_remove_last:
        \__kernel_displayblock_beginpar_hmode:w \par
      }
    \legacy_if:nTF { @inlabel }
      {
        \legacy_if_set_true:n { @noparitem }
        \legacy_if_set_true:n { @noparlist }
      }
      {
        \legacy_if:nT { @newlist } { \@noitemerr }
        \legacy_if_set_false:n { @noparlist }
        \skip_set_eq:NN \l__block_effective_top_skip \l__block_topsepadd_skip
      }
    \skip_add:Nn \l__block_effective_top_skip { \parskip }
    \skip_zero:N \leftskip
    \skip_set_eq:NN \rightskip \@rightskip
    \skip_set_eq:NN \parfillskip \@flushglue
    \int_zero:N \par@deathcycles
    \@setpar
      {
        \legacy_if:nTF { @newlist }
          {
            \int_incr:N \par@deathcycles
            \int_compare:nNnTF \par@deathcycles > { 1000 }
                { \@noitemerr
                  { \para_end: }
                }
          }
          {
            { \para_end: }
          }
      }
    \skip_set_eq:NN \@outerparskip \parskip
    \skip_set_eq:NN \parskip \parsep
    \dim_set_eq:NN \parindent \listparindent
    \dim_add:Nn \linewidth { - \rightmargin - \leftmargin }
    \dim_add:Nn \@totalleftmargin { \leftmargin }
    \tex_parshape:D 1 ~ \@totalleftmargin \linewidth
    \__kernel_displayblock_begin:
    \legacy_if:nTF { @noparitem }
      {
        \legacy_if_set_false:n { @noparitem }
        \hbox_gset:Nn \g__block_labels_box
          {
            \skip_horizontal:n { - \leftmargin }
            \hbox_unpack_drop:N \g__block_labels_box
            \skip_horizontal:n { \leftmargin }
          }
        \legacy_if:nF { @minipage } % Why this chunk of code?
          {
            \__block_skip_set_to_last:N \l__block_tmpa_skip
            \skip_vertical:n { - \l__block_tmpa_skip }
            \skip_vertical:n { \l__block_tmpa_skip + \@outerparskip - \parskip }
          }
      }
      {
        \legacy_if:nTF { @nobreak }
          { \addvspace{\skip_eval:n{\@outerparskip-\parskip}} }
          {
            \addpenalty \@beginparpenalty
            \addvspace \l__block_effective_top_skip
            \addvspace{-\parskip}
          }
      }
}
\keys_define:nn { template/block/display }
{
  ,topsep        .skip_set:N = \topsep
  ,partopsep     .skip_set:N = \partopsep
  ,listparindent .skip_set:N = \listparindent
}
\cs_new:Npn \__kernel_displayblock_begin: {
  \__block_debug_typeout:n{\detokenize{__kernel_displayblock_begin:}}
}
\cs_new:Npn \__kernel_displayblock_beginpar_hmode:w {
  \__block_debug_typeout:n{\detokenize{__kernel_displayblock_beginpar_hmode:w}}
}
\cs_new:Npn \__kernel_displayblock_beginpar_vmode: {
  \__block_debug_typeout:n{\detokenize{__kernel_displayblock_beginpar_vmode:}}
}
\tl_new:N \@itemlabel         % should have a top-level definition
\tl_new:N \@listctr           % should have a top-level definition
\DeclareTemplateCode{list}{std}{1}
{
  counter         = \l__block_counter_tl,
  item-label      = \l__block_item_label_tl,
  start           = \l__block_counter_start_int ,
  resume          = \l__block_resume_bool ,
  item-instance   = \__block_item_instance:n ,
  item-skip       = \itemsep ,
  item-penalty    = \@itempenalty ,
  item-indent     = \itemindent ,
  label-width     = \labelwidth ,
  label-sep       = \labelsep ,
  legacy-support  = \l__block_legacy_support_bool , % FMi questionable
}
{
  \__block_debug_typeout:n{template:list:std}
  \tl_if_empty:nF {#1} { \SetTemplateKeys{list}{std}{#1} }
  \tl_if_empty:NTF \l__block_counter_tl
    {
     \tl_if_blank:oF \@listctr
       {
         \bool_if:NF \l__block_resume_bool
           {
             \int_gset:cn{ c@ \@listctr }
                 { \l__block_counter_start_int - 1 }
           }
       }
       { \@nmbrlistfalse }
    }
    {
     \@nmbrlisttrue
     \tl_set_eq:NN \@listctr \l__block_counter_tl
     \bool_if:NF \l__block_resume_bool
       {
         \int_gset:cn{ c@ \@listctr }
             { \l__block_counter_start_int - 1 }
       }
    }
  \tl_if_empty:NF \l__block_item_label_tl
    {
      \tl_set_eq:NN \@itemlabel \l__block_item_label_tl
    }
    \legacy_if_gset_true:n { @newlist }
  \__block_debug_typeout:n{template:list:std~end}
}
\keys_define:nn { template/list/std }
{
  ,nosep .code:n =
    \dim_zero:N \itemsep
    \dim_zero:N \parsep
    \dim_zero:N \topsep
    \dim_zero:N \l__block_botsep_skip
    \dim_zero:N \l__block_parbotsep_skip
  ,midsep    .skip_set:N = \topsep
}
\keys_define:nn { template/item/std }
                { label .tl_set:N = \l__block_label_given_tl }
\DeclareTemplateCode{item}{std}{1}
  {
    counter-label   = \__block_counter_label:n ,
    counter-ref     = \__block_counter_ref:n ,
    label-ref       = \__block_label_ref:n ,
    label-autoref   = \__block_label_autoref:n ,
    label-format    = \__block_label_format:n ,
    label-strut     = \l__block_label_strut_bool ,
    label-boxed     = \l__block_label_boxed_bool ,
    next-line       = \l__block_next_line_bool ,
    text-font       = \l__block_text_font_tl ,
    compatibility   = \l__block_item_compatibility_bool ,
    label-align     = {
      left    = \tl_set:Nn \l__block_item_align_tl { \relax \hss } ,
      center  = \tl_set:Nn \l__block_item_align_tl { \hss \hss } ,
      right   = \tl_set:Nn \l__block_item_align_tl { \hss \relax } ,
      parleft = \NOT_IMPLEMENTED ,
    } ,
  }
  {
    \__block_debug_typeout:n{template:item:std}
    \tl_set_eq:NN \l__block_label_given_tl \c_novalue_tl
    \tl_if_empty:nF{#1}{ \SetTemplateKeys{item}{std}{#1} }
    \tl_if_novalue:oTF \l__block_label_given_tl
      {
        \tl_if_blank:oF \@listctr { \@kernel@refstepcounter \@listctr }
        \bool_if:NTF \l__block_item_compatibility_bool   % not sure that conditional
                                                     % makes sense
          { \__block_make_label_box:n { \MakeLinkTarget[\@listctr]{}\@itemlabel } } % TODO ?
          { \__block_make_label_box:n { \MakeLinkTarget[\@listctr]{}\__block_counter_label:n { \@listctr } } }
      }
      {
        \__block_debug_typeout:n{item~ with~ optional}
        \__block_make_label_box:n { \l__block_label_given_tl } }
    \bool_if:nT
      {
        \l__block_label_boxed_bool
        && \dim_compare_p:n { \box_wd:N \l__block_one_label_box <= \linewidth } % TODO: is \linewidth correct?
      }
      {
        \dim_compare:nNnT
          { \box_wd:N \l__block_one_label_box } < \labelwidth
          {
            \hbox_set_to_wd:Nnn \l__block_one_label_box { \labelwidth }
              {
                \exp_after:wN \use_i:nn \l__block_item_align_tl
                \box_use_drop:N \l__block_one_label_box
                \exp_after:wN \use_ii:nn \l__block_item_align_tl
              }
          }
       \hbox_set:Nn \l__block_one_label_box
                    { \box_use_drop:N \l__block_one_label_box }
      }
    \dim_compare:nNnTF { \box_wd:N \l__block_one_label_box } > \labelwidth
      { \bool_set_true:N \l__block_long_label_bool }
      { \bool_set_false:N \l__block_long_label_bool }
    \hbox_gset:Nn \g__block_labels_box
      {
        \hbox_unpack_drop:N \g__block_labels_box
        \skip_horizontal:n { \itemindent - \labelsep - \labelwidth }
        \hbox_unpack_drop:N \l__block_one_label_box
        \skip_horizontal:n { \labelsep }
        \bool_if:NT \l__block_next_line_bool
          { \bool_if:NT \l__block_long_label_bool { \nobreak \hfil \break } }
        % version of \newline inside an hbox that will be unpacked
      }
    % \skip_set_eq:NN \parsep \l__block_item_parsep_skip TODO??? FMi
                                                           % what's that?
    \dim_set_eq:NN \parindent \listparindent
    \cs_set_eq:NN \__block_item_everypar: \__block_item_everypar_std:
  }
\box_new:N \l__block_one_label_box
\box_new:N \g__block_labels_box
\bool_new:N \l__block_long_label_bool
\cs_new_protected:Npn \__block_make_label_box:n #1
  {
    \hbox_set:Nn \l__block_one_label_box
      {
        \__kernel_list_label_begin:
        \__block_label_format:n
          {
            \bool_if:NT \l__block_label_strut_bool { \strut }
            \bool_if:NTF \l__block_legacy_support_bool
                         \makelabel
                         \use:n
                 {#1}
          }
        \__kernel_list_label_end:
      }
  }
\cs_new_eq:NN \__kernel_list_label_begin: \prg_do_nothing:
\cs_new_eq:NN \__kernel_list_label_end:   \prg_do_nothing:
\cs_new_eq:NN \__block_item_everypar: \prg_do_nothing:
\AddToHook{para/begin}[lists]{\__block_item_everypar:}
\DeclareHookRule{para/begin}{lists}{after}{tagpdf}
\cs_new_protected:Npn \__block_item_everypar_std: {
    \__block_debug_typeout:n{item~ everypar \on@line }
    \legacy_if_set_false:n { @minipage }
    \legacy_if_gset_false:n { @newlist }
    \legacy_if:nT { @inlabel }
       {
         \legacy_if_gset_false:n { @inlabel }
         \box_if_empty:NT \g_para_indent_box { \kern - \itemindent }
         \para_omit_indent:
         \box_use_drop:N \g__block_labels_box
         \__kernel_list_label_after:
         \penalty \c_zero_int
       }
   \legacy_if:nTF { @nobreak }
       {
         \legacy_if_gset_false:n { @nobreak }
         \int_set:Nn \clubpenalty { 10000 }
       }
       {
         \int_set_eq:NN \clubpenalty \@clubpenalty
         \cs_set_eq:NN \__block_item_everypar: \prg_do_nothing:
       }
}
\cs_new_eq:NN \__kernel_list_label_after: \prg_do_nothing:
\skip_new:N \l__block_tmpa_skip
\skip_new:N \l__block_topsepadd_skip
\skip_new:N \l__block_effective_top_skip
\AddToHook{begindocument/before}{
  \RenewDocumentCommand{\item}{ ={label}o }
    {
      \@inmatherr \item
      \cs_if_free:NTF \__block_item_instance:n
        {
          \@latex@error{Lonely~\string\item--perhaps~a~missing~
          list~environment}\@ehc
        }
        {
          \legacy_if:nTF { @newlist }
            { \__kernel_list_item_begin: }
            { \__block_inter_item:            }
          \tl_if_novalue:nTF {#1}          % avoids reparsing label={}
            { \__block_item_instance:n { } }
            { \__block_item_instance:n {#1} }
          \legacy_if_gset_true:n { @inlabel }
          \ignorespaces
        }
    }
}
\cs_new_protected:Npn \__block_inter_item: {
  \legacy_if:nT { @inlabel }
                { \indent \par } % case of \item\item
   \mode_if_horizontal:T { \__block_skip_remove_last:
                           \__block_skip_remove_last: \par }
  \__kernel_list_item_end:
  \__kernel_list_item_begin:
  \addpenalty \@itempenalty
  \addvspace \itemsep
}
\cs_new_eq:NN \__kernel_list_item_begin: \prg_do_nothing:
\cs_new_eq:NN \__kernel_list_item_end:   \prg_do_nothing:
\cs_new:Npn \__block_recipe_basic: {
  \cs_set_eq:NN \__kernel_displayblock_beginpar_hmode:w
                                              \__block_beginpar_hmode:N
  \cs_set_eq:NN \__kernel_displayblock_beginpar_vmode:
                                              \__block_beginpar_vmode:
  \let \__kernel_displayblock_begin:          \prg_do_nothing:
  \let \__kernel_displayblock_end:            \prg_do_nothing:
  \socket_assign_plug:nn{tagsupport/block-endpe}{on}
}
\cs_new:Npn \__block_recipe_standalone: {
  \cs_set_eq:NN \__kernel_displayblock_beginpar_hmode:w
                                              \prg_do_nothing:
  \cs_set_eq:NN \__kernel_displayblock_beginpar_vmode:
                                              \prg_do_nothing:
  \cs_set_eq:NN \__kernel_displayblock_begin: \__block_inner_begin:
  \cs_set_eq:NN \__kernel_displayblock_end:   \__block_inner_end:
  \socket_assign_plug:nn{tagsupport/block-endpe}{off}
  \tl_if_empty:NTF \l__block_tag_name_tl
     { \tl_set:Nn    \l__block_tag_inner_tag_tl {Sect}            }
     { \tl_set_eq:NN \l__block_tag_inner_tag_tl \l__block_tag_name_tl }
}
\cs_new:Npn \__block_recipe_standard:
{
  \cs_set_eq:NN \__kernel_displayblock_beginpar_hmode:w
                                              \__block_beginpar_hmode:N
  \cs_set_eq:NN \__kernel_displayblock_beginpar_vmode:
                                              \__block_beginpar_vmode:
  \cs_set_eq:NN \__kernel_displayblock_begin: \__block_inner_begin:
  \cs_set_eq:NN \__kernel_displayblock_end:   \__block_inner_end:
  \socket_assign_plug:nn{tagsupport/block-endpe}{on}
  \tl_if_empty:NTF \l__block_tag_name_tl
     { \tl_set:Nn    \l__block_tag_inner_tag_tl {Figure}          }
     { \tl_set_eq:NN \l__block_tag_inner_tag_tl \l__block_tag_name_tl }
}
\tl_new:N \l__block_tag_inner_tag_tl
\cs_new:Npn \__block_recipe_list:
{
  \cs_set_eq:NN \__kernel_displayblock_beginpar_hmode:w
                                              \__block_beginpar_hmode:N
  \cs_set_eq:NN \__kernel_displayblock_beginpar_vmode:
                                              \__block_beginpar_vmode:
  \cs_set_eq:NN \__kernel_displayblock_begin: \__block_list_begin:
  \cs_set_eq:NN \__kernel_displayblock_end:   \__block_list_end:
  \cs_set_eq:NN \__kernel_list_item_begin:    \__block_list_item_begin:
  \cs_set_eq:NN \__kernel_list_item_end:      \__block_list_item_end:
  \socket_assign_plug:nn{tagsupport/block-endpe}{on}
  \tl_if_empty:NTF \l__block_tag_name_tl
     { \tl_set:Nn    \l__tag_L_tag_tl {L}               }
     { \tl_set_eq:NN \l__tag_L_tag_tl \l__block_tag_name_tl }
  \tl_if_empty:NTF \l__block_tag_class_tl
     { \tl_set:Nn    \l__tag_L_attr_class_tl {}                 }
     { \tl_set_eq:NN \l__tag_L_attr_class_tl \l__block_tag_class_tl }
}

\DeclareInstance{blockenv}{displayblock}{display}
{
  env-name       = displayblock,
  tag-name       = ,
  tag-class      = ,
  tagging-recipe = standard,
  inner-level-counter  = ,
  level-increase = false,
  setup-code     = ,
  block-instance = displayblock ,
  inner-instance = ,
}
\DeclareInstance{blockenv}{displayblockflattened}{display}
{
  env-name       = displayblockflattened,
  tag-name       = ,
  tag-class      = ,
  tagging-recipe = basic,
  inner-level-counter  = ,
  level-increase = false,
  setup-code     = ,
  block-instance = displayblock ,
  para-flattened = true ,
  inner-instance = ,
}
\DeclareInstance{blockenv}{center}{display}
{
  env-name       = center,
  tag-name       = ,
  tag-class      = ,
  tagging-recipe = basic,
  inner-level-counter  = ,
  level-increase = false,
  setup-code     = ,
  block-instance = displayblock ,
  para-flattened = true ,
  para-instance  = center ,
  inner-instance = ,
}
\DeclareInstance{blockenv}{flushleft}{display}
{
  env-name       = flushleft,
  tag-name       = ,
  tag-class      = ,
  tagging-recipe = basic,
  inner-level-counter  = ,
  level-increase = false,
  setup-code     = ,
  block-instance = displayblock ,
  para-flattened = true ,
  para-instance  = raggedright ,
  inner-instance = ,
}
\DeclareInstance{blockenv}{flushright}{display}
{
  env-name       = flushleft,
  tag-name       = ,
  tag-class      = ,
  tagging-recipe = basic,
  inner-level-counter  = ,
  level-increase = false,
  setup-code     = ,
  block-instance = displayblock ,
  para-flattened = true ,
  para-instance  = raggedleft ,
  inner-instance = ,
}
   %
\DeclareInstance{blockenv}{quotation}{display}
{
  env-name       = quotation,
  tag-name       = quotation,
  tag-class      = ,
  tagging-recipe = standard,
  inner-level-counter  = ,
  level-increase = true,
  setup-code     = ,
  block-instance = quotationblock ,
  inner-instance =  ,
}
\DeclareInstance{blockenv}{quote}{display}
{
  env-name       = quote,
  tag-name       = quote,
  tag-class      = ,
  tagging-recipe = standard,
  inner-level-counter  = ,
  level-increase = true,
  setup-code     = ,
  block-instance = quoteblock ,
  inner-instance =  ,
}

\DeclareInstance{blockenv}{theorem}{display}
{
  env-name       = theorem-like,
  tag-name       = theorem-like,
  tag-class      = ,
  tagging-recipe = standalone,
  inner-level-counter  = ,
  level-increase = false,
  setup-code     = ,
  block-instance = displayblock ,
}
\DeclareInstance{blockenv}{verbatim}{display}
{
  env-name       = verbatim,
  tag-name       = verbatim,
  tag-class      = ,
  tagging-recipe = standard,
  inner-level-counter  = ,
  level-increase = false,
  setup-code     = ,
  block-instance = verbatimblock ,
  inner-instance = ,
  final-code     = \legacyverbatimsetup ,
}
\DeclareInstance{blockenv}{itemize}{display}
{
  env-name       = itemize,
  tag-name       = itemize,
  tag-class      = itemize,
  tagging-recipe = list,
  inner-level-counter  = \@itemdepth,
  level-increase = true,
  max-inner-levels = 4,
  setup-code     = ,
  block-instance = list ,
  inner-instance = itemize ,
}
\DeclareInstance{blockenv}{enumerate}{display}
{
  env-name            = enumerate,
  tag-name            = enumerate,
  tag-class           = enumerate,
  tagging-recipe      = list,
  level-increase      = true,
  setup-code          = ,
  block-instance      = list ,
  inner-level-counter = \@enumdepth,
  max-inner-levels    = 4,
  inner-instance      = enum ,
}

\DeclareInstance{blockenv}{description}{display}
{
  env-name       = description,
  tag-name       = description,
  tag-class      = description,
  tagging-recipe = list,
  inner-level-counter  = ,
  level-increase = true,
  setup-code     = ,
  block-instance = list ,
  inner-instance = description ,
}
\DeclareInstance{blockenv}{list}{display}
{
  env-name       = list,
  tag-name       = list,
  tag-class      = ,
  tagging-recipe = list,
  level-increase = true,
  setup-code     = \legacylistsetupcode ,
  block-instance = list ,
  inner-level-counter  = ,
  inner-instance = legacy ,
}
\setcounter{maxblocklevels}{6}
\DeclareInstance{block}{displayblock-0}{display}
  {
    leftmargin      = 0pt ,
    parindent       = 0pt ,
  }
\DeclareInstanceCopy{block}{displayblock-1}{displayblock-0}
\DeclareInstanceCopy{block}{displayblock-2}{displayblock-0}
\DeclareInstanceCopy{block}{displayblock-3}{displayblock-0}
\DeclareInstanceCopy{block}{displayblock-4}{displayblock-0}
\DeclareInstanceCopy{block}{displayblock-5}{displayblock-0}
\DeclareInstanceCopy{block}{displayblock-6}{displayblock-0}
\DeclareInstance{block}{verbatimblock-0}{display}
  {
    leftmargin      = 0pt ,
    parindent       = 0pt ,
    par-skip        = 0pt ,
  }
\DeclareInstanceCopy{block}{verbatimblock-1}{verbatimblock-0}
\DeclareInstanceCopy{block}{verbatimblock-2}{verbatimblock-0}
\DeclareInstanceCopy{block}{verbatimblock-3}{verbatimblock-0}
\DeclareInstanceCopy{block}{verbatimblock-4}{verbatimblock-0}
\DeclareInstanceCopy{block}{verbatimblock-5}{verbatimblock-0}
\DeclareInstanceCopy{block}{verbatimblock-6}{verbatimblock-0}
\DeclareInstance{block}{quoteblock-1}{display}
  { rightmargin = \KeyValue{leftmargin} }
\DeclareInstanceCopy{block}{quoteblock-2}{quoteblock-1}
\DeclareInstanceCopy{block}{quoteblock-3}{quoteblock-1}
\DeclareInstanceCopy{block}{quoteblock-4}{quoteblock-1}
\DeclareInstanceCopy{block}{quoteblock-5}{quoteblock-1}
\DeclareInstanceCopy{block}{quoteblock-6}{quoteblock-1}
\DeclareInstance{block}{quotationblock-1}{display}
  { parindent = 1.5em , rightmargin = \KeyValue{leftmargin} }
\DeclareInstanceCopy{block}{quotationblock-2}{quotationblock-1}
\DeclareInstanceCopy{block}{quotationblock-3}{quotationblock-1}
\DeclareInstanceCopy{block}{quotationblock-4}{quotationblock-1}
\DeclareInstanceCopy{block}{quotationblock-5}{quotationblock-1}
\DeclareInstanceCopy{block}{quotationblock-6}{quotationblock-1}
\DeclareInstance{block}{list-1}{display}{
}
\DeclareInstance{block}{list-2}{display}{}
\DeclareInstance{block}{list-3}{display}{}
\DeclareInstance{block}{list-4}{display}{}
\DeclareInstance{block}{list-5}{display}{}
\DeclareInstance{block}{list-6}{display}{}
\DeclareInstance{list}{itemize-1}{std}{ item-label = \labelitemi }
\DeclareInstance{list}{itemize-2}{std}{ item-label = \labelitemii }
\DeclareInstance{list}{itemize-3}{std}{ item-label = \labelitemiii }
\DeclareInstance{list}{itemize-4}{std}{ item-label = \labelitemiv }
\DeclareInstance{list}{enum-1}{std}
  { item-label = \labelenumi ,   counter = enumi }
\DeclareInstance{list}{enum-2}{std}
  { item-label = \labelenumii ,  counter = enumii }
\DeclareInstance{list}{enum-3}{std}
  { item-label = \labelenumiii , counter = enumiii }
\DeclareInstance{list}{enum-4}{std}
  { item-label = \labelenumiv ,  counter = enumiv }
\DeclareInstance{list}{legacy}{std} {
  item-instance = basic ,
  legacy-support = true ,
}
\DeclareInstance{list}{description}{std} { item-instance = description }
\DeclareInstance{item}{basic}{std}
  {
    label-align = right ,
  }
\DeclareInstance{item}{description}{std}
  {
    label-format = \normalfont\bfseries #1 ,
    label-align = left
  }
\tag_if_active:T
{
  \tagpdfsetup
      {
        newattribute = {justify}    {/O /Layout /TextAlign/Justify},
        newattribute = {center}     {/O /Layout /TextAlign/Center},
        newattribute = {raggedright}{/O /Layout /TextAlign/Start},
        newattribute = {raggedleft} {/O /Layout /TextAlign/End},
      }
}
\DeclareInstance{para}{center}{std}
{
  indent-width          = 0pt ,
  start-skip            = 0pt ,
  left-skip             = \@flushglue ,
  right-skip            = \@flushglue ,
  end-skip              = \z@skip ,
  final-hyphen-demerits = 0 ,
  cr-cmd                = \@centercr ,
  para-class            = center ,
}
\DeclareInstance{para}{raggedright}{std}
{
  indent-width          = 0pt ,
  start-skip            = 0pt ,
  left-skip             = \z@skip ,
  right-skip            = \@flushglue ,
  end-skip              = \z@skip ,
  final-hyphen-demerits = 0 ,
  cr-cmd                = \@centercr ,
  para-class            = raggedright ,
}
\DeclareInstance{para}{raggedleft}{std}
{
  indent-width          = 0pt ,
  start-skip            = 0pt ,
  left-skip             = \@flushglue ,
  right-skip            = \z@skip ,
  end-skip              = \z@skip ,
  final-hyphen-demerits = 0 ,
  cr-cmd                = \@centercr ,
  para-class            = raggedleft ,
}
\DeclareInstance{para}{justify}{std}
{
  start-skip            = 0pt ,
  left-skip             = \z@skip ,
  right-skip            = \z@skip ,
  end-skip              = \@flushglue ,
  final-hyphen-demerits =  5000 ,
  cr-cmd                = \@normalcr ,
  para-class            = justify ,
}
\DeclareRobustCommand\centering  {\UseInstance{para}{center}{}}
\DeclareRobustCommand\raggedleft {\UseInstance{para}{raggedleft}{}}
\DeclareRobustCommand\raggedright{\UseInstance{para}{raggedright}{}}
\DeclareRobustCommand\justifying {\UseInstance{para}{justify}{}}

\justifying
\tag_if_active:TF {
  \cs_set:Npn \__block_beginpar_vmode: {
           \__block_debug_typeout:n
              { @endpe = \legacy_if:nTF { @endpe }{true}{false}
                \on@line }
   \legacy_if:nTF { @endpe }
      {
        \legacy_if_gset_false:n { @endpe }
      }
      {
        \int_compare:nNnT \l__block_flattened_level_int < 2
            {
              \__tag_gincr_para_main_begin_int:
              \tag_struct_begin:n
                {
                  tag=\l__tag_para_main_tag_tl,
                  attribute-class=\l__tag_para_main_attr_class_tl,
                }
            }
      }
  }
  \cs_set:Npn \__block_beginpar_hmode:N #1
     {
        \tag_mc_end:
        \__tag_gincr_para_end_int:
        \__block_debug_typeout:n{increment~ /P \on@line }
        \bool_if:NT \l__tag_para_show_bool
          { \tag_mc_begin:n{artifact}
            \rlap{\color_select:n{red}\tiny\ \int_use:N\g__tag_para_end_int}
            \tag_mc_end:
          }
        \tag_struct_end:
        \tagpdfparaOff \par \tagpdfparaOn
     }
\cs_set:Npn \__kernel_displayblock_doendpe: {
     \bool_if:NT \l__tag_para_bool
       {
         \legacy_if:nT { @endpe }
           {
             \__block_debug_typeout:n
                { flattened= \bool_if:NTF
                               \l__tag_para_flattened_bool {true}{false}
                  \on@line }
             \bool_if:NF \l__tag_para_flattened_bool
               {
                 \__block_debug_typeout:n{Structure-end~
                   \l__tag_para_main_tag_tl\space after~ displayblock \on@line }
                 \__tag_gincr_para_main_end_int:
                 \tag_struct_end: %text-unit
               }
           }
      }
}
\RemoveFromHook{para/begin}[tagpdf]
\AddToHook{para/begin}[tagpdf]{
  \bool_if:NT \l__tag_para_bool {
       \legacy_if:nF { @inlabel }
         {
           \__block_start_para_structure:n { \PARALABEL }
         }
     }
}
\cs_new_protected:Npn \__block_start_para_structure:n #1 {
   \__block_debug_typeout:n
      { @endpe = \legacy_if:nTF { @endpe }{true}{false}
        \on@line }
   \legacy_if:nF { @endpe }
     {
       \bool_if:NF \l__tag_para_flattened_bool
          {
            \__tag_gincr_para_main_begin_int:
            \tag_struct_begin:n
              {
                tag=\l__tag_para_main_tag_tl,
                attribute-class=\l__tag_para_main_attr_class_tl,
              }
          }
      }
   \__tag_gincr_para_begin_int:
   \__block_debug_typeout:n{increment~ P \on@line }
   \tag_struct_begin:n
       {
          tag=\l__tag_para_tag_tl
         ,attribute-class=\l__tag_para_attr_class_tl
       }
   \__tag_check_para_begin_show:nn {green}{#1}
   \tag_mc_begin:n {}
}
\cs_new_protected:Npn \__block_start_para_structure_unconditionally:n #1 {
   \bool_if:NF \l__tag_para_flattened_bool
       {
         \__tag_gincr_para_main_begin_int:
         \tag_struct_begin:n
           {
             tag=\l__tag_para_main_tag_tl,
             attribute-class=\l__tag_para_main_attr_class_tl,
           }
       }
   \__tag_gincr_para_begin_int:
   \__block_debug_typeout:n{increment~ P \on@line }
   \tag_struct_begin:n
       {
          tag=\l__tag_para_tag_tl
         ,attribute-class=\l__tag_para_attr_class_tl
       }
   \__tag_check_para_begin_show:nn {green}{#1}
   \tag_mc_begin:n {}
}
\RemoveFromHook{para/end}[tagpdf]
\AddToHook{para/end}
  {
    \bool_if:NT \l__tag_para_bool
      {
        \__tag_gincr_para_end_int:
        \__block_debug_typeout:n{increment~ /P \on@line }
        \tag_mc_end:
        \__tag_check_para_end_show:nn {red}{}
        \tag_struct_end:
        \bool_if:NF \l__tag_para_flattened_bool
         {
           \__tag_gincr_para_main_end_int:
           \tag_struct_end:
         }
      }
  }
\def\PARALABEL{NP-}
\cs_set_protected:Npn \para_end: {
  \scan_stop:
  \mode_if_horizontal:TF {
    \mode_if_inner:F {
         \tex_unskip:D
         \hook_use:n{para/end}
         \@kernel@after@para@end
         \mode_if_horizontal:TF {
           \if_int_compare:w 11 = \tex_lastnodetype:D
             \tex_hskip:D \c_zero_dim
           \fi:
           \tex_par:D
           \hook_use:n{para/after}
           \@kernel@after@para@after
         }
         { \msg_error:nnnn { hooks }{ para-mode }{end}{horizontal} }
    }
  }
  {
    \__kernel_endpe_vmode:       % should do nothing if no tagging
    \tex_par:D
  }
}
\cs_set_eq:NN \par     \para_end:
\cs_set_eq:NN \__blockpar   \para_end:
\cs_set_eq:NN \endgraf \para_end:
\DeclareRobustCommand*\begin[1]{%
  \UseHook{env/#1/before}%
  \@ifundefined{#1}%
    {\def\reserved@a{\@latex@error{Environment~#1~undefined}\@eha}}%
    {\def\reserved@a{\def\@currenvir{#1}%
        \edef\@currenvline{\on@line}%
        \@execute@begin@hook{#1}%
        \csname #1\endcsname}}%
  \@ignorefalse
  \begingroup
    \__kernel_endpe_vmode:
    \reserved@a}
\cs_new:Npn \__kernel_endpe_vmode: {
    \if@endpe \ifvmode
      \bool_if:NT \l__tag_para_bool
{
  \bool_if:NF \l__tag_para_flattened_bool
   {
     \__tag_gincr_para_main_end_int:
     \tag_struct_end:
   }
   \@endpefalse
}
    \fi \fi
}
\cs_set:Npn \__kernel_list_label_after: {
   \bool_if:NT \l__tag_para_bool
     {
       \__block_start_para_structure_unconditionally:n { LI- }
     }
}
\cs_new:Npn \__block_inner_begin: {
  \tagstructbegin{tag=\l__block_tag_inner_tag_tl}
}
\cs_new:Npn \__block_inner_end: {
  \__block_debug_typeout:n{block-end \on@line}
  \legacy_if:nT { @endpe }
    {
      \__tag_gincr_para_main_end_int:
      \__block_debug_typeout:n{close~ /text-unit \on@line}
      \tagstructend
    }
  \tagstructend        % end inner structure
}
\tl_new:N  \l__tag_L_tag_tl
\tl_set:Nn \l__tag_L_tag_tl {L}

\tl_new:N\l__tag_L_attr_class_tl
\tl_set:Nn \l__tag_L_attr_class_tl {list}
\tag_if_active:T
{
  \tagpdfsetup
      {
        % default if unknown
        newattribute = {list}{/O /List /ListNumbering/None},
        newattribute = {itemize}{/O /List /ListNumbering/Unordered},
        newattribute = {enumerate}{/O /List /ListNumbering/Ordered},
        newattribute = {description}{/O /List /ListNumbering/Description},
      }
}
\def\LItag{LI}
\cs_set:Npn \__block_list_begin: {
  \tagstructbegin
      {
         tag=\l__tag_L_tag_tl
        ,attribute-class=\l__tag_L_attr_class_tl
      }
}
\cs_set:Npn \__block_list_item_begin: { \tagstructbegin{tag=\LItag} }
\cs_set:Npn \__kernel_list_label_begin: {
       \tagstructbegin{tag=Lbl}
       \tagmcbegin{tag=Lbl}
}
\cs_set:Npn \__kernel_list_label_end: {
  \tagmcend                                    % end mc-Lbl or artifact
         \tagstructend   % end   Lbl
  \tagstructbegin{tag=\LBody}
}
\def\LBody{LBody}
\cs_set:Npn \__block_list_item_end: {
  \legacy_if:nT { @endpe }
    {
      \__tag_gincr_para_main_end_int:
      \tagstructend                           % text-unit
    }
  \tagstructend \tagstructend   % end LBody, LI
}
\cs_set:Npn \__block_list_end: {
  \legacy_if:nT { @endpe }
    {
      \__tag_gincr_para_main_end_int:
      \tagstructend                       % text-unit
      \__block_debug_typeout:n{Structure-end~ P~ at~ list-end \on@line }
    }
  \tagstructend\tagstructend  % end LBody, LI
  \tagstructend               % end L
}
}
{
  \cs_new:Npn \__block_start_para_structure_unconditionally:n #1 {}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endinput
%%
%% End of file `latex-lab-testphase-block.sty'.
