%%
%% This is file `hgeneric-testphase.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% hyperref-generic.dtx  (with options: `package')
%% 
%% Copyright (C) 2019-2021 The LaTeX Project
%% 
%% It may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License (LPPL), either version 1.3c of
%% this license or (at your option) any later version.  The latest
%% version of this license is in the file:
%% 
%%    https://www.latex-project.org/lppl.txt
%% 
%% This file is part of the "LaTeX PDF management testphase bundle" (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%% 
%% File: hyperref-generic.dtx
\ProvidesFile{hgeneric-testphase.def}[2025-03-26 v0.96q %
  generic Hyperref driver for the LaTeX PDF management testphase bundle]

\RequirePackage{etoolbox} %why?
\long\def\Hy@ReturnAfterFi#1\fi{\fi#1}
\ExplSyntaxOn
\file_input:n {hyperref-colorschemes.def}
\ExplSyntaxOff
\ExplSyntaxOn
\prop_gput:Nnn \g_msg_module_name_prop { hyp }{ hyperref }
\cs_if_exist:NTF \DocumentMetadata
  {
   \msg_new:nnnn
      { hyp }
      { missing-resource-management }
      { The~PDF~resource~management~is~required~for~this~hyperref~driver! }
      {
         Activate~it~with \\
         \tl_to_str:n{\DocumentMetadata{<options>}}\\
         before~\tl_to_str:n{\documentclass}
      }
  }
  {
    \msg_new:nnnn
      { hyp }
      { missing-resource-management }
      { The~PDF~resource~management~is~required~for~this~hyperref~driver! }
      {
         Activate~it~with \\
         \tl_to_str:n{\RequirePackage{pdfmanagement-testphase}}\\
         \tl_to_str:n{\DocumentMetadata{<options>}}\\
         before~\tl_to_str:n{\documentclass}
      }
   }
\msg_new:nnnn
  { hyp }
  { pdfversion-disabled }
  {
    This~hyperref~driver~ignores~the~pdfversion~key!\\
    Set~the~pdfversion~in~\token_to_str:N \DocumentMetadata
  }
  {
    For example:\\
    \tl_to_str:n
     {
      \DocumentMetadata { pdfversion=1.7 }
     }
  }
\msg_new:nnn
  { hyp }
  { key-dropped }
  {
    This~hyperref~driver~ignores~the~key~#1!\\
    Please~check~the~documentation.
  }
\msg_new:nnn
  { hyp }
  { pdfa-no-push-button }
  { PDF/A:~Push~button~with~JavaScript~is~prohibited }

\msg_new:nnn
  { hyp }
  { pdfa-no-reset-button }
  { PDF/A:~Reset~action~is~prohibited }
\msg_new:nnn
  { hyp }
  { pdfa-no-named-action }
  { PDF/A:~Named~action~#1~is~prohibited }
\msg_new:nnn
  { hyp }
  { empty-destination-name }
  {
    Empty~destination~name,\\
            using~'#1'
  }
\msg_new:nnn
  { hyp }
  { invalid-destination-value }
  {
    Invalid~value~'#1'~of~'#2'  \\
    is~replaced~by~'Fit'~\msg_line_context:.
  }
\msg_new:nnn
  { hyp }
  { ignore-deprecated-or-unknown-option-in-pdf-version }
  {
    Option~'#1'~is~unknown~or~deprecated~in\\
    pdf~version~#2.~Ignored.
  }
\msg_new:nnn
  { hyp }
  { ignore-deprecated-or-unknown-value-in-pdf-version }
  {
    Value~'#1'~is~unknown~or~deprecated~in\\
    pdf~version~#2.~Ignored.
  }
\msg_new:nnn
  { hyp }
  { replace-deprecated-or-unknown-value-in-pdf-version }
  {
    Value~'#1'~is~unknown~or~deprecated~in\\
    pdf~version~#2. Value~'#3'~is used instead.
  }
\msg_new:nnn
  { hyp }
  { unknown-key }
  {
    unknown~key~#2~of~module~'#1'~set~to~'#3'.
  }
\msg_new:nnn
  { hyp }
  { unknown-key-to-Hyp }
  {
    ignored~in~family~Hyp~unknown~key~#1.
  }
\cs_new:Npn \__hyp_clist_display:n #1 {*~#1\\}
\msg_new:nnn
  { hyp }
  { unknown-choice }
  {
    Value~'#3'~is~invalid~for~key~'#1'.\\
    The~key~accepts~only~the~choices\\
    \clist_map_function:nN { #2 }\__hyp_clist_display:n
  }

\msg_new:nnn
  { hyp }
  { unknown-choice+empty }
  {
    Value~'#3'~is~invalid~for~key~'#1'.\\
    The~key~accepts~only~the~choices\\
    \clist_map_function:nN { #2 }\__hyp_clist_display:n
    An~empty~value~removes~the~setting.
  }

\msg_new:nnn
  { hyp }
  { no-bool }
  {
    Value~'#2'~is~invalid~for~key~'#1'.\\
    The~key~accepts~only~the~choices\\
    *~true\\
    *~false \\
    *~and~an~empty~value~which~removes~the~setting.\\
    No~value~is~equivalent~to~using~'true'.
  }
\msg_new:nnn
  { hyp }
  { empty-info-value }
  {
    Empty~value~for~key~#1.\\
    This~isn't~honored~by~all~backends.
  }
\cs_generate_variant:Nn\pdf_destination:nn {nf}
\cs_generate_variant:Nn\pdf_object_ref:n {e}
\cs_generate_variant:Nn\pdf_pageobject_ref:n {e}
\chardef\Hy@VersionChecked=1 %don't check the version!
\cs_set_eq:NN \hypercalcbp \dim_to_decimal_in_bp:n
\providecommand\@pdfborder{}
\providecommand\@pdfborderstyle{}
\newcommand\OBJ@OCG@view {} % needed in hyperref
\def\Hy@numberline#1{#1\c_space_tl}   %needed by bookmark
\cs_set_eq:NN \Hy@pdfminorversion \pdf_version_minor:
\cs_set_eq:NN \Hy@pdfmajorversion \pdf_version_major:
\legacy_if:nT { Hy@setpdfversion }
 {
    \msg_warning:nn { hyp }{ pdfversion-disabled }
 }
\Hy@DisableOption{pdfversion}
\RenewDocumentCommand \Acrobatmenu { m m }
  {
    \hyper@linknamed {#1} {#2}
  }
\cs_set_protected:Npn \hypersetup #1
  {
     %\kvsetkeys{Hyp} {#1}
     \keys_set:nn { hyp }{ #1 }
  }
\keys_define:nn { hyp }
  {
    unknown .code:n =
    {
      \msg_warning:nneee { hyp } { unknown-key }
      { hyp }{ \l_keys_key_str } { #1 }
    }
  }
\keys_define:nn { hyp }
  {
    next-anchor .code:n =
    {
      \AddToHookNext{__hyp/dest/make}
       {\Hy@MakeCurrentHref{#1}}
    }
  }

\bool_new:N \l__hyp_href_url_encode_bool
\bool_new:N \l__hyp_href_url_ismap_bool
\tl_new:N   \l__hyp_href_url_protocol_tl
\tl_new:N   \l__hyp_href_pdf_destination_tl
\tl_new:N   \l__hyp_href_pdf_page_tl
\tl_new:N   \l__hyp_href_run_parameter_tl
\cs_new_protected:Npn \__hyp_href_url_format: {\begingroup\Url}

\keys_define:nn { hyp / href }
  {
    ,urlencode  .bool_set:N =  \l__hyp_href_url_encode_bool
    ,format     .code:n = { \cs_set:Nn \__hyp_href_url_format: {#1} },
    ,protocol  .tl_set:N   =  \l__hyp_href_url_protocol_tl
    ,destination .tl_set:N = \l__hyp_href_pdf_destination_tl
    ,pdfremotestartview .code:n =
      {
        \keys_set:nn { hyp }
          { pdfremotestartview = #1 }
      }
    ,page .code:n =
      {
       \tl_set:Nn \l__hyp_href_pdf_page_tl {#1}
       \tl_set:Nn \Hy@href@page {#1}
      }
    ,ismap  .bool_set:N  = \l__hyp_href_url_ismap_bool
    ,run-parameter .tl_set:N = \l__hyp_href_run_parameter_tl
    ,nextactionraw .code:n =
     { %perhaps some safety match later, see hyperref code
       \tl_if_empty:nTF {#1}
         {
           \pdfdict_remove:nn{l_hyp/annot/A}{Next}
         }
         {
           \pdfdict_put:nnn{l_hyp/annot/A}{Next}{#1}
           \tl_set:Nn \Hy@href@nextactionraw {/Next~#1}
           \keys_set:nn {hyp }{ pdfnewwindow = true}
         }
     }
    ,afrelationship .code:n =
      {
        \pdfdict_put:nne
          { l_pdffile/Filespec}{AFRelationship}{ \pdf_name_from_unicode_e:n {#1}}
      }

  }

\keys_define:nn { hyp }
  {
    ,href / urlencode .bool_set:N =  \l__hyp_href_url_encode_bool
    ,href / urlencode .default:n  = {true}
    ,href / urlencode .initial:n  = {false}
    ,href / protocol  .tl_set:N   =   \l__hyp_href_url_protocol_tl
    ,href / destination .tl_set:N = \l__hyp_href_pdf_destination_tl
    ,href / format  .code:n = { \cs_set:Nn \__hyp_href_url_format:{#1} }
  }

\hook_new_pair:nn{cmd/href/before}{cmd/href/after}

\DeclareRobustCommand*{\href}[1][]{%
  \mode_leave_vertical:
  \hook_use:n{cmd/href/before}
  \group_begin:
  \keys_set:nn { hyp / href } {#1}
  \bool_if:NTF \l__hyp_href_url_encode_bool
    {
      \tl_set:Nn \l__hyp_text_enc_uri_print_tl {utf8/URI}
    }
    {
      \tl_set:Nn \l__hyp_text_enc_uri_print_tl {utf8/string}
    }
  \@ifnextchar\bgroup\Hy@href{\hyper@normalise\href@}%
}

\begingroup
  \catcode`\$=6 %
  \catcode`\#=12 %
  \gdef\href@$1{\expandafter\href@split$1##\\}%
  \gdef\href@split$1#$2#$3\\$4{%
    \hyper@@link{$1}{$2}{$4}%<---__hyp-docstrip doubling!
    \endgroup
    \hook_use:n{cmd/href/after}
  }%
\endgroup

\hook_new_pair:nn{cmd/hrefurl/before}{cmd/hrefurl/after}

\DeclareRobustCommand*{\hrefurl}[1][]
 {
   \mode_leave_vertical:
   \hook_use:n{cmd/href/before}
   \group_begin:
   \keys_set:nn { hyp / href } {#1}
   \bool_if:NTF \l__hyp_href_url_encode_bool
    {
      \tl_set:Nn \l__hyp_text_enc_uri_print_tl {utf8/URI}
    }
    {
      \tl_set:Nn \l__hyp_text_enc_uri_print_tl {utf8/string}
    }
  \hyper@normalise\__hyp_href_url_aux:nn}

\cs_new_protected:Npn \__hyp_href_url_aux:nn #1 #2
  {
    \exp_args:Nno\hyper@linkurl{#2}{\l__hyp_href_url_protocol_tl#1}
    \group_end:
    \hook_use:n{cmd/href/after}
  }

\hook_new_pair:nn{cmd/hrefpdf/before}{cmd/hrefpdf/after}
\DeclareRobustCommand*{\hrefpdf}[1][]
 {
  \mode_leave_vertical:
  \hook_use:n{cmd/hrefpdf/before}
  \group_begin:
  \keys_set:nn { hyp / href } {#1}
  \hyper@normalise\__hyp_href_pdf_aux:nn
 }

\cs_new_protected:Npn \__hyp_href_pdf_aux:nn #1 #2
  {
    \exp_args:Nnno\hyper@linkfile{#2}{#1}{\l__hyp_href_pdf_destination_tl}
    \group_end:
    \hook_use:n{cmd/hrefpdf/after}
  }

\hook_new_pair:nn{cmd/hrefrun/before}{cmd/hrefrun/after}
\DeclareRobustCommand*{\hrefrun}[1][]
 {
  \mode_leave_vertical:
  \hook_use:n{cmd/hrefrun/before}
  \group_begin:
  \keys_set:nn { hyp / href } {#1}
  \hyper@normalise\__hyp_href_run_aux:nn
 }

\cs_new_protected:Npn \__hyp_href_run_aux:nn #1 #2
  {
    \exp_args:Nnno\hyper@linklaunch{#1}{#2}{\l__hyp_href_run_parameter_tl}
    \group_end:
    \hook_use:n{cmd/hrefrun/after}
  }

\hook_new_pair:nn{cmd/url/before}{cmd/url/after}

\DeclareRobustCommand*{\url}[1][]
  {
   \mode_leave_vertical:
   \hook_use:n{cmd/url/before}
   \group_begin:
   \keys_set:nn {hyp / href } {#1}
    \bool_if:NTF \l__hyp_href_url_encode_bool
    {
      \tl_set:Nn \l__hyp_text_enc_uri_print_tl {utf8/URI}
    }
    {
      \tl_set:Nn \l__hyp_text_enc_uri_print_tl {utf8/string}
    }
   \hyper@normalise\__hyp_href_url_aux:n
  }

\cs_new_protected:Npn \__hyp_href_url_aux:n #1
 {
   \exp_args:Nno
     \hyper@linkurl{\__hyp_href_url_format: {#1}}
     {\l__hyp_href_url_protocol_tl#1}
   \group_end:
   \hook_use:n{cmd/url/after}
 }


\def\urldef#1#2{\begingroup\def\url{\hyper@normalise\url@}\setbox\z@\hbox\bgroup
  \def\Url@HyperHook##1\endgroup{\Url@def{#1}{#2}}%
  % Because hyperref breaks \urldef and does not define its own (Grrrr!)...
  \def\url@##1{\egroup\endgroup\DeclareRobustCommand#1{#2{##1}}}%
 #2}

\NewExpandableDocumentCommand\__hyp_secondoftwowithopt:wnn {omm}{#3}
\pdfstringdefDisableCommands{\let\hrefurl\__hyp_secondoftwowithopt:wnn}
\pdfstringdefDisableCommands{\let\hrefpdf\__hyp_secondoftwowithopt:wnn}
\pdfstringdefDisableCommands{\let\hrefrun\__hyp_secondoftwowithopt:wnn}
\cs_new_protected:Npn \__hyp_store_metadata:nn #1 #2 %#1 key, #2 value.
  {
    %\tl_set:cn {@#1}{#2}
    \AddToDocumentProperties[hyperref]{#1}{#2}
  }
\cs_generate_variant:Nn \__hyp_store_metadata:nn {en,ne,ee,no,eo}
\hook_new:n{hyp/link/cite}
\keys_define:nn { hyp }
  {
    ,citecolor .code:n = {\__hyp_color_set:ne {hyp/color/cite}{#1}\__hyp_citecolor_hook_init:}
    ,citebordercolor
      .code:n = {\__hyp_color_set:ne {hyp/color/citeborder}{#1}\__hyp_citebordercolor_hook_init:}
  }
\cs_new_protected:Npn \__hyp_citecolor_hook_init:
 {
   \hook_gput_code:nnn { hyp/link/cite }{hyp/cite}
     {
       \keys_set:nn { hyp }
         {
           linkcolor      = hyp/color/cite
         }
     }
  \cs_gset_eq:NN \__hyp_citecolor_hook_init: \prg_do_nothing:
  }
\cs_new_protected:Npn \__hyp_citebordercolor_hook_init:
 {
   \hook_gput_code:nnn { hyp/link/cite }{hyp/citeborder}
     {
       \keys_set:nn { hyp }
         {
           linkbordercolor      = hyp/color/citeborder
         }
     }
  \cs_gset_eq:NN \__hyp_citebordercolor_hook_init: \prg_do_nothing:
  }

\bool_lazy_and:nnF
  { \cs_if_exist_p:N \pdfmanagement_if_active_p: }{ \pdfmanagement_if_active_p: }
  { \msg_error:nn { hyp}{ missing-resource-management } }
\AddToHook { package/bookmark/after}
 {
   \define@key{BKM}{color}
     {
      \tl_if_blank:nTF {#1}
        { \cs_set_eq:NN\BKM@color\@empty }
        {
          \__hyp_color_set:ne {__hyp/tmpa}{#1}
          \color_export:nVN
            {__hyp/tmpa}
            \g__hyp_bordercolormodel_str
            \BKM@color
        }
     }
 }
\legacy_if:nTF { Hy@bookmarks }
  {
    \AddToHook{begindocument/before}[hyperref/bookmark]
     {
       \RequirePackage{bookmark}
     }
  }
  {
    \AddToHook{begindocument/before}[hyperref/bookmark]{}
  }
\legacy_if:nT {Hy@draft}
  {
    \PassOptionsToPackage{draft}{bookmark}
  }
\cs_new_protected:Npn \__hyp_property_record:nn #1 #2 %label/attributes
 {
   \@bsphack
     \property_record:nn{#1}{#2}
   \@esphack
 }
\cs_generate_variant:Nn \__hyp_property_record:nn {ee}
\box_new:N \l__hyp_tmpa_box
\tl_new:N  \l__hyp_tmpa_tl
\tl_new:N  \l__hyp_tmpb_tl
\seq_new:N \l__hyp_tmpa_seq
\int_new:N \l__hyp_tmpa_int
\str_new:N \l__hyp_tmpa_str
\tl_new:N  \l__hyp_dest_name_tmpa_tl
\tl_new:N  \l__hyp_uri_tmpa_tl
\tl_new:N  \l__hyp_filename_tmpa_tl
\tl_new:N  \l__hyp_para_tmpa_tl
\str_new:N \l__hyp_text_tmpa_str
\str_new:N \g__hyp_text_tmpa_str
\tl_const:Nn \c__hyp_dest_undefined_tl {UNDEFINED}
\seq_const_from_clist:Nn \c__hyp_annot_types_seq
 {url,link,file,menu,run}
\prop_const_from_keyval:Nn \c__hyp_map_annot_hyp_prop
  {
    URI   = url,
    GoTo  = link,
    GoToR = file,
    Named = menu,
    Launch= run
  }
\prop_const_from_keyval:Nn \c__hyp_map_hyp_annot_prop
  {
    url   = URI,
    link  = GoTo,
    file  = GoToR,
    menu  = Named,
    run   = Launch
  }

\tl_new:N  \g__hyp_dest_pdfstartpage_tl
\tl_new:N  \g__hyp_dest_pdfstartview_tl
\tl_new:N  \l__hyp_dest_pdfremotestartview_tl
\tl_new:N  \l__hyp_text_enc_uri_print_tl
\tl_new:N  \l__hyp_text_enc_info_print_tl
\tl_new:N  \l__hyp_text_enc_dest_tl
\tl_new:N  \l__hyp_text_enc_dest_print_tl
\tl_new:N  \l__hyp_text_enc_file_print_tl
\tl_new:N  \l__hyp_text_enc_para_print_tl

\tl_set:Nn \l__hyp_text_enc_uri_print_tl  {utf8/URI}
\tl_set:Nn \l__hyp_text_enc_info_print_tl {utf16/hex}
\tl_set:Nn \l__hyp_text_enc_dest_tl       {utf8/string-raw}
\tl_set:Nn \l__hyp_text_enc_dest_print_tl {utf8/string}
\tl_set:Nn \l__hyp_text_enc_file_print_tl {utf8/string}
\tl_set:Nn \l__hyp_text_enc_para_print_tl {utf8/string}
\tl_new:N\l__hyp_link_Contents_tl
\socket_new:nn {hyp/link/GoTo/Contents}{2}
\socket_new:nn {hyp/link/URI/Contents}{1}
\socket_new_plug:nnn {hyp/link/GoTo/Contents}{default}
  {
    \__hyp_text_pdfstring:eoN
      { Go~to~destination~#1  }
      { \l__hyp_text_enc_info_print_tl }
      \l__hyp_link_Contents_tl
    \pdfannot_dict_put:nne {link/GoTo}{Contents}
      {\l__hyp_link_Contents_tl}
  }
\socket_new_plug:nnn {hyp/link/URI/Contents}{default}
  {
    \__hyp_text_pdfstring:eoN
      { #1  }
      { \l__hyp_text_enc_info_print_tl }
      \l__hyp_link_Contents_tl
    \pdfannot_dict_put:nne {link/URI}{Contents}
      {\l__hyp_link_Contents_tl}
  }
\socket_assign_plug:nn{hyp/link/GoTo/Contents}{default}
\socket_assign_plug:nn{hyp/link/URI/Contents}{default}
\tl_new:N  \l__hyp_dest_pdfview_tl
\str_new:N \g__hyp_bordercolormodel_str
\seq_map_inline:Nn \c__hyp_annot_types_seq
  {
    \bool_new:c {l_hyp_annot_color#1_bool}
  }
\seq_map_inline:Nn \c__hyp_annot_types_seq
  {
    \bool_new:c {l_hyp_annot_ocgcolor#1_bool}
  }
\seq_map_inline:Nn \c_pdfannot_link_types_seq
  {
    \bool_new:c {l__hyp_annot_#1_bool}
    \bool_set_true:c {l__hyp_annot_#1_bool}
  }
\box_new:N  \l__hyp_dest_box

\regex_const:Nn \c__hyp_dest_startview_regex
  {
    \A\ *
     (?:
      (?:XYZ (?:\ +(?:(?:\d+|\d*\.\d+)|null)){3}\ )
      |
      (?:Fit\b|FitB\b)
      |
      (?:(?:FitH|FitV|FitBH|FitBV)(?:\ +(?:\d+|\d*\.\d+)|\ +null){1})
      |
      (?:FitR (?:\ +\d+|\ +\d*\.\d+){4}\ )
     )
  }
\pdfdict_new:n   {l__hyp_page/Trans}
\pdfdict_put:nnn {l__hyp_page/Trans}{Type}{/Trans}

\hook_new:n {hyp/text/pdfstring}
\cs_new_protected:Npn \__hyp_text_purify:nN #1 #2 %#1 input, #2  str command
  {
     \str_set:Ne #2 {\text_purify:n { #1 } }
  }
\cs_new_protected:Npn \__hyp_text_cleanup:N #1
 {

 }
\cs_new_protected:Npn \__hyp_text_string_from_unicode:nN #1 #2
  {
     \pdf_string_from_unicode:nVN { #1 } #2 #2
  }
\cs_new_protected:Npn \__hyp_text_pdfstring:nnN #1 #2 #3
  {
    \group_begin:
    \Hy@pdfstringtrue
    \hook_use:n {hyp/text/pdfstring}
    \__hyp_text_purify:nN  { #1 } \l__hyp_text_tmpa_str
    \__hyp_text_cleanup:N         \l__hyp_text_tmpa_str
    \__hyp_text_string_from_unicode:nN { #2 } \l__hyp_text_tmpa_str
    \str_gset_eq:NN \g__hyp_text_tmpa_str\l__hyp_text_tmpa_str
    \group_end:
    \str_set_eq:NN #3 \g__hyp_text_tmpa_str
 }
\cs_generate_variant:Nn \__hyp_text_pdfstring:nnN {enN,onN,eoN,ooN,noN}
\cs_new_protected:Npn\Hy@pstringdef #1 #2
  { \__hyp_text_pdfstring:enN {#2} {utf8/string-raw}#1 }
\cs_new_protected:Npn \__hyp_text_pdfstring_info:nN #1 #2
  {
    \__hyp_text_pdfstring:noN  { #1 }{ \l__hyp_text_enc_info_print_tl } #2
  }
\cs_generate_variant:Nn \__hyp_text_pdfstring_info:nN {eN,oN}
\cs_new_protected:Npn\__hyp_PageLabels_gpush:
  {
    \pdfmanagement_add:nne {Catalog} {PageLabels}{<</Nums[\HyPL@Labels]>>}
  }

\def\Hy@PutCatalog #1 {}

\legacy_if:nT { Hy@pdfpagelabels }
  {
    \cs_set_protected:Npn \HyPL@StorePageLabel #1
      {
        \tl_gput_right:Ne \HyPL@Labels { \the\Hy@abspage<<#1>> }
        \__hyp_PageLabels_gpush:
      }
  }
\int_new:N \g__hyp_linknestlevel_int
\prg_new_conditional:Npnn \__hyp_if_outer_link: {TF}
 {
   \int_compare:nNnTF { \g__hyp_linknestlevel_int } > {1}
     { \prg_return_false:  }
     { \prg_return_true: }
 }

\cs_new:Npn \__hyp_check_link_nesting:TF #1 #2
 {
   \use_i:nn {#1}{#2}
 }
\keys_define:nn { hyp }
  {
    nested-links .choice:,
    nested-links / true .code:n =
     { \cs_set_eq:NN \__hyp_check_link_nesting:TF \use_i:nn },
    nested-links / false .code:n =
     { \cs_set_eq:NN \__hyp_check_link_nesting:TF \__hyp_if_outer_link:TF },
    nested-links .default:n = {true}
  }
\Hy@WrapperDef \__hyp_destination:nn #1 #2
  {
    \mode_if_horizontal:T { \@savsf\spacefactor }
    \Hy@SaveLastskip      %defined in hyperref
    \Hy@VerboseAnchor{#1} %defined in hyperref, for debugging
    \__hyp_text_pdfstring:eoN
      { \HyperDestNameFilter{#1}  }
      { \l__hyp_text_enc_dest_tl }
      \l__hyp_tmpa_tl
    \str_if_eq:nnTF  {#2} {fitrbox}
      {
        \exp_args:NV
        \pdf_destination:nnnn \l__hyp_tmpa_tl
         { \box_wd:N \l__hyp_dest_box }
         { \box_ht:N \l__hyp_dest_box }
         { \box_dp:N \l__hyp_dest_box }
      }
      {
        \exp_args:NV
          \pdf_destination:nf
          { \l__hyp_tmpa_tl }
          { #2 }
      }
    \Hy@RestoreLastskip   %defined in hyperref
    \mode_if_horizontal:T { \spacefactor\@savsf }
  }
\tl_new:N\l_hyp_current_dest_name_tl
\hook_new:n{hyp/anchor}
\cs_new_protected:Npn \hyper@anchor #1
  {
    \exp_args:NnV
      \__hyp_destination:nn {#1} \l__hyp_dest_pdfview_tl
    \tl_set:Nn \l_hyp_current_dest_name_tl {#1}
    \hook_use:n{hyp/anchor}
  }

\cs_new_protected:Npn \hyper@anchorstart #1
  {
    \Hy@activeanchortrue
    \exp_args:NnV
      \__hyp_destination:nn {#1} \l__hyp_dest_pdfview_tl
    \tl_set:Nn \l_hyp_current_dest_name_tl {#1}
    \hook_use:n{hyp/anchor}
  }

\cs_new_protected:Npn \hyper@anchorend
  {
    \Hy@activeanchorfalse
  }
\cs_new_protected:Npn \__hyp_link_goto_begin:nw #1
  {
    \mode_leave_vertical:
    \protected@edef \l__hyp_dest_name_tmpa_tl { #1 }
    \tl_if_empty:NTF \l__hyp_dest_name_tmpa_tl
      {
        \msg_warning:nne
          { hyp }
          { empty-destination-name }
          { \c__hyp_dest_undefined_tl }
        \tl_set_eq:NN \l__hyp_dest_name_tmpa_tl \c__hyp_dest_undefined_tl
      }
      {
        \__hyp_text_pdfstring:eoN
          { \exp_args:No \HyperDestNameFilter { \l__hyp_dest_name_tmpa_tl } }
          { \l__hyp_text_enc_dest_tl }
          \l__hyp_dest_name_tmpa_tl
      }
    \exp_args:No
      \pdfannot_link_goto_begin:nw  { \l__hyp_dest_name_tmpa_tl }
  }

\cs_new_protected:Npn \__hyp_link_goto_end:
  {
    \pdfannot_link_goto_end:
  }


\cs_new_protected:Npn \hyper@link #1 #2 #3 %#1 context, #2=destination name, #3 content
  {
    \bool_if:NTF \l__hyp_annot_GoTo_bool
      {
        \int_gincr:N\g__hyp_linknestlevel_int
        \__hyp_check_link_nesting:TF
          {
            \Hy@VerboseLinkStart{#1}{#2}
            \group_begin:
            \tl_set:Nn \l_hyp_current_dest_name_tl {#2}
            \socket_use:nnn{hyp/link/GoTo/Contents}{#2}{#3}
            \hook_use:n {hyp/link/#1}
            \__hyp_link_goto_begin:nw {#2}#3\Hy@xspace@end
            \__hyp_link_goto_end:
            \group_end:
            \Hy@VerboseLinkStop
          }
          {
            \group_begin: #3\group_end:
          }
        \int_gdecr:N\g__hyp_linknestlevel_int
      }
      {{\let\protect\relax#3}}
  }
\cs_new_protected:Npn \hyper@linkstart #1 #2 %#1 context, #2=destination name
  {
    \bool_if:NT \l__hyp_annot_GoTo_bool
      {
        \int_gincr:N\g__hyp_linknestlevel_int
        \__hyp_check_link_nesting:TF
          {
            \Hy@VerboseLinkStart{#1}{#2}% only for debug
            \group_begin:
            \tl_set:Nn \l_hyp_current_dest_name_tl {#2}
            \socket_use:nnn{hyp/link/GoTo/Contents}{#2}{}
            \hook_use:n {hyp/link/#1}
            \__hyp_link_goto_begin:nw {#2}
          }
          {
            \group_begin:
          }
      }
  }

\cs_new_protected:Npn \hyper@linkend
  {
    \bool_if:NT \l__hyp_annot_GoTo_bool
      {
        \__hyp_check_link_nesting:TF
          {
            \__hyp_link_goto_end:
            \group_end:
            \Hy@VerboseLinkStop
          }
          {
            \group_end:
          }
        \int_gdecr:N\g__hyp_linknestlevel_int
      }
  }
\pdfdict_new:n   {l_hyp/annot/A/URI}
\pdfdict_put:nnn {l_hyp/annot/A/URI}{Type}{/Action}
\pdfdict_put:nnn {l_hyp/annot/A/URI}{S}{/URI}

\cs_new_protected:Npn \hyper@linkurl #1 #2  %#1:link text #2: URI,
  {
    \bool_if:NTF \l__hyp_annot_URI_bool
      {
        \int_gincr:N\g__hyp_linknestlevel_int
        \__hyp_check_link_nesting:TF
          {
           \group_begin:
            \__hyp_text_pdfstring:eoN
              { #2}
              { \l__hyp_text_enc_uri_print_tl }
              \l__hyp_uri_tmpa_tl
            \pdfdict_put:nno{l_hyp/annot/A/URI}{URI}{\l__hyp_uri_tmpa_tl}
            \bool_if:NT \l__hyp_href_url_ismap_bool
              {
               \pdfdict_put:nnn{l_hyp/annot/A/URI}{IsMap}{true}
              }
            \socket_use:nn{hyp/link/URI/Contents}{#2}
            \cs_set_eq:NN \# \c_hash_str
            \cs_set_eq:NN \% \c_percent_str
            \Hy@safe@activestrue
            \mode_leave_vertical:
            \pdfannot_dict_put:nne {link/URI}{A}{<<\pdfdict_use:n {l_hyp/annot/A/URI}>>}
            \pdfannot_link:nen { URI }
              {
              }
              {
                \let\protect\relax
                #1
                \Hy@xspace@end
                \Hy@VerboseLinkStop %where is the start??
              }
            \group_end:
           }
           {
             \group_begin: #1 \group_end:
           }
         \int_gdecr:N\g__hyp_linknestlevel_int
      }
      {{\let\protect\relax#1}}
  }

\pdfdict_new:n   {l_hyp/annot/A/GoToR}
\pdfdict_put:nnn {l_hyp/annot/A/GoToR}{Type}{/Action}
\pdfdict_put:nnn {l_hyp/annot/A/GoToR}{S}{/GoToR}

\cs_generate_variant:Nn \pdffile_embed_file:nnn {noe}
\cs_new_protected:Npn \hyper@linkfile #1 #2 #3 % link text, filename, destname
  {
   \bool_if:NTF \l__hyp_annot_GoToR_bool
     {
        \int_gincr:N\g__hyp_linknestlevel_int
        \__hyp_check_link_nesting:TF
          {
            \group_begin:
            \tl_set:Ne \l__hyp_filename_tmpa_tl { \text_expand:n { #2 } }
            \exp_args:Ne
              \pdf_object_if_exist:nF { __hyp_file_\tl_to_str:N \l__hyp_filename_tmpa_tl }
                {
                  \pdfdict_put:nne { l_pdffile/Filespec}{Subtype}{\pdf_name_from_unicode_e:n {application/pdf}}
                  \pdffile_embed_file:noe
                    {}
                    {\l__hyp_filename_tmpa_tl }
                    {__hyp_file_\tl_to_str:N \l__hyp_filename_tmpa_tl }
                }
            \pdfdict_put:nne
               {l_hyp/annot/A/GoToR}
               {F}
               {\pdf_object_ref:e {__hyp_file_\tl_to_str:N \l__hyp_filename_tmpa_tl}}
            \__hyp_text_pdfstring:nnN
              { #3 }
              { \l__hyp_text_enc_dest_print_tl }
              \l__hyp_dest_name_tmpa_tl
            \tl_if_blank:eTF {#3}
              {
                \pdfdict_put:nne {l_hyp/annot/A/GoToR}{D}
                  {
                   [
                     \int_eval:n
                      { \int_max:nn {0}{ 0\l__hyp_href_pdf_page_tl - 1 }}
                     /\l__hyp_dest_pdfremotestartview_tl
                   ]
                  }
              }
              {
                \pdfdict_put:nno {l_hyp/annot/A/GoToR}{D}{\l__hyp_dest_name_tmpa_tl}
              }
            \mode_leave_vertical:
            \pdf_object_unnamed_write:ne{dict}{\pdfdict_use:n {l_hyp/annot/A/GoToR}}
            \pdfannot_dict_put:nne {link/GoToR}{A}{\pdf_object_ref_last:}
            \pdfannot_link:nnn %expansion??
              { GoToR }
              {
              }
              {
               \let\protect\relax
                #1\Hy@xspace@end
                \Hy@VerboseLinkStop %where is the start??
              }
            \group_end:
          }
          {
            \group_begin: #1 \group_end:
          }
        \int_gdecr:N\g__hyp_linknestlevel_int
     }
     {{\let\protect\relax#1}}
  }
\pdfdict_new:n   {l_hyp/annot/A/Launch}
\pdfdict_put:nnn {l_hyp/annot/A/Launch}{Type}{/Action}
\pdfdict_put:nnn {l_hyp/annot/A/Launch}{S}{/Launch}

\cs_new_protected:Npn \hyper@linklaunch #1 #2 #3 % filename, link text, Parameters
  {
   \bool_if:NTF \l__hyp_annot_Launch_bool
     {
        \int_gincr:N\g__hyp_linknestlevel_int
        \__hyp_check_link_nesting:TF
          {
           \group_begin:
             \__hyp_text_pdfstring:nnN
               { #1 }
               { \l__hyp_text_enc_file_print_tl }
               \l__hyp_filename_tmpa_tl
             \pdfdict_put:nno {l_hyp/annot/A/Launch}{F}{\l__hyp_filename_tmpa_tl}
             \__hyp_text_pdfstring:noN
               { #3 }
               { \l__hyp_text_enc_para_print_tl }
               \l__hyp_para_tmpa_tl
             \bool_if:nTF
               {
                 \str_if_eq_p:Vn \l__hyp_para_tmpa_tl {()}
                 ||
                 \pdf_version_compare_p:Nn > {1.9}
               }
               {
                 \pdfdict_remove:nn {l_hyp/annot/A/Launch}{Win}
               }
               {
                 \pdfdict_put:nne
                   {l_hyp/annot/A/Launch}
                   {Win}
                   {<</P \l__hyp_para_tmpa_tl /F \l__hyp_filename_tmpa_tl >>}
               }
             \mode_leave_vertical:
             \pdfannot_dict_put:nne {link/Launch}{A}{<<\pdfdict_use:n {l_hyp/annot/A/Launch}>>}
             \pdfannot_link:nen
               { Launch }
               {
     %            /A
   %              <<
   %                \pdfdict_use:n {l_hyp/annot/A/Launch}
   %              >>
               }
               {
                 \let\protect\relax
                 #2\Hy@xspace@end
                 \Hy@VerboseLinkStop %where is the start??
               }
           \group_end:
          }
          { \group_begin: #2 \group_end: }
        \int_gdecr:N\g__hyp_linknestlevel_int
      }
      {{\let\protect\relax#2}}
  }
\use:e
  { % filename, anchor text, linkname
    \cs_set_protected:Npn \exp_not:N \@hyper@launch run \c_colon_str #1 \exp_not:N \\ #2 #3
  }
  {
    \hyper@linklaunch {#1}{#2}{#3}
  }
\pdfdict_new:n   {l_hyp/annot/A/Named}
\pdfdict_put:nnn {l_hyp/annot/A/Named}{Type}{/Action}
\pdfdict_put:nnn {l_hyp/annot/A/Named}{S}{/Named}

\cs_new_protected:Npn \hyper@linknamed #1 #2 %#1 action, #2 link text
  {
    \bool_if:NTF \l__hyp_annot_Named_bool
      {
         \int_gincr:N\g__hyp_linknestlevel_int
         \__hyp_check_link_nesting:TF
          {
            \group_begin:
            \pdfmeta_standard_verify:nnTF {named_actions}{#1}
              {
                \mode_leave_vertical:
                \pdfdict_put:nne {l_hyp/annot/A/Named}{N}
                  {\pdf_name_from_unicode_e:n{#1}}
                \pdfannot_dict_put:nne {link/Named}{A}{<<\pdfdict_use:n {l_hyp/annot/A/Named}>>}
                \pdfannot_link:nnn { Named }
                 {
   %                /A
   %                  <<
   %                    \pdfdict_use:n { l_hyp/annot/A/Named }
   %                  >>
                 }
                 {
                   #2
                   \Hy@xspace@end
                   \Hy@VerboseLinkStop
                 }
              }
              {
                \msg_warning:nnn { hyp } { pdfa-no-named-action }{#1}
                #2
              }
           \group_end:
          }
          { \group_begin: #2 \group_end: }
        \int_gdecr:N\g__hyp_linknestlevel_int
      }
      {{\let\protect\relax#2}}
  }

\cs_generate_variant:Nn \color_export:nnN {nVN}
\cs_new_protected:Npn \__hyp_color_select:n #1
 {
   \tl_if_head_eq_charcode:nNTF {#1}[ %]
    {
      \__hyp_color_select_aux:wn  #1
    }
    {
      \color_select:n {#1}
    }
 }

\cs_new_protected:Npn \__hyp_color_select_aux:wn  [#1] #2
  {
     \color_select:nn {#1}{#2}
  }

\cs_generate_variant:Nn \__hyp_color_select:n {e}
\cs_new_protected:Npn \__hyp_color_set:nn #1 #2
 {
   \tl_if_head_eq_charcode:nNTF {#2}[ %]
    {
      \__hyp_color_set_aux:nwn  { #1 } #2
    }
    {
      \color_set:nn {#1} {#2}
    }
 }

\cs_new_protected:Npn \__hyp_color_set_aux:nwn #1 [#2] #3
  {
     \color_set:nnn {#1}{#2}{#3}
  }

\cs_generate_variant:Nn \__hyp_color_set:nn {ne}
\prop_map_inline:Nn \c__hyp_map_hyp_annot_prop
  {
     \hook_gput_code:nnn
       {pdfannot/link/#2/begin}
       {hyp/color}
       {
         \bool_if:cT { l_hyp_annot_color#1_bool }
           {
             \group_begin:
             \color_select:n { hyp/color/#1}
           }
       }
     \hook_gput_code:nnn
       {pdfannot/link/#2/end}
       {hyp/color}
       {
         \bool_if:cT { l_hyp_annot_color#1_bool }
           {
             \group_end:
           }
       }
  }
\keys_define:nn { hyp }
  {
    ,colorlinks .choice:
    ,colorlinks / true  .meta:n =
      {
        ,pdfborder={0~0~0}
        ,pdfborderstyle=
        ,colorurl  =#1
        ,colorlink =#1
        ,colorrun  =#1
        ,colormenu =#1
        ,colorfile =#1
        }
    ,colorlinks / false  .meta:n =
      {
        ,colorurl  =#1
        ,colorlink =#1
        ,colorrun  =#1
        ,colormenu =#1
        ,colorfile =#1
        }
    ,colorlinks .default:n = {true}
  }
\seq_map_inline:Nn \c__hyp_annot_types_seq
  {
     \keys_define:nn { hyp }
       {
         ,color#1 .bool_set:c = { l_hyp_annot_color#1_bool }
         ,#1color .code:n =     { \__hyp_color_set:ne {hyp/color/#1}{##1} }
       }
  }

\keys_define:nn { hyp }
  {
    ,allcolors .meta:n =
      {
        ,urlcolor=#1
        ,linkcolor=#1
        ,runcolor=#1
        ,filecolor=#1
        ,menucolor=#1
      }
    ,allcolors .value_required:n = true
  }
\keys_define:nn { hyp }
  {
    ,bordercolormodel .choices:nn =
     {rgb,cmyk}
     { \str_gset:Nn \g__hyp_bordercolormodel_str {space-sep-#1}}
    ,bordercolormodel .initial:n ={rgb}
  }
\prop_map_inline:Nn \c__hyp_map_hyp_annot_prop
  {
    \keys_define:nn { hyp }
      {
        #1bordercolor .code:n =
          {
             \tl_if_empty:nTF { ##1 }
               {
                 \pdfannot_dict_remove:nn
                  {link/#2}
                  { C }
               }
               {
                 \__hyp_color_set:ne {hyp/color/#1border}{##1}
                 \color_export:nVN
                   {hyp/color/#1border}
                   \g__hyp_bordercolormodel_str
                   \l__hyp_tmpa_tl
                 \pdfannot_dict_put:nne
                   {link/#2}
                   { C }
                   { [\l__hyp_tmpa_tl] }
               }
          }
      }
  }

\keys_define:nn { hyp }
  {
    ,allbordercolors .meta:n =
      {
        ,linkbordercolor=#1
        ,urlbordercolor =#1
        ,filebordercolor=#1
        ,menubordercolor=#1
        ,runbordercolor =#1
      }
    ,allbordercolors .value_required:n = true
  }

\prop_map_inline:Nn \c__hyp_map_hyp_annot_prop
  {
    \keys_define:nn { hyp }
      {
        #1border .code:n =
          {
             \tl_if_empty:nTF { ##1 }
               {
                 \pdfannot_dict_remove:nn
                  {link/#2}
                  { Border }
               }
               {
                 \pdfannot_dict_put:nnn
                   {link/#2}
                   { Border }
                   { [##1] }
               }
          }
      }
  }
\keys_define:nn { hyp }
  {
    ,pdfborder  .code:n =
      {
        \tl_if_empty:nTF { #1 }
         {
           \prop_map_inline:Nn \c__hyp_map_hyp_annot_prop
             {
               \pdfannot_dict_remove:nn
                  {link/##2}
                  { Border }
             }
         }
         {
           \prop_map_inline:Nn \c__hyp_map_hyp_annot_prop
             {
               \pdfannot_dict_put:nnn
                 {link/##2}
                 { Border }
                 { [#1] }
             }
         }
      }
    ,pdfborder .initial:n = {0~0~1},
  }
\prop_map_inline:Nn \c__hyp_map_hyp_annot_prop
  {
    \keys_define:nn { hyp }
      {
        #1borderstyle .code:n =
          {
             \tl_if_empty:nTF { ##1 }
               {
                 \pdfannot_dict_remove:nn
                  {link/#2}
                  { BS }
               }
               {
                 \pdfannot_dict_put:nnn
                   {link/#2}
                   { BS }
                   { <<##1>> }
               }
          }
      }
  }
\keys_define:nn { hyp }
  {
    ,pdfborderstyle  .code:n =
      {
        \tl_if_empty:nTF { #1 }
         {
           \prop_map_inline:Nn \c__hyp_map_hyp_annot_prop
             {
               \pdfannot_dict_remove:nn
                  {link/##2}
                  { BS }
             }
         }
         {
           \prop_map_inline:Nn \c__hyp_map_hyp_annot_prop
             {
               \pdfannot_dict_put:nnn
                 {link/##2}
                 { BS }
                 { <<#1>> }
             }
         }
      }
    ,pdfborderstyle .initial:n = {},
  }
\cs_new_protected:Npn \__hyp_ocg_init:
  {
     \pdf_object_new:n   { __hyp/OCG/View }
     \pdf_object_new:n   { __hyp/OCG/Print }
     \pdf_object_new:n   { __hyp/OCG/config }
     \pdf_object_new:n   { __hyp/OCG/refarray }
        \pdf_object_write:nne { __hyp/OCG/refarray } { array }
          {
            \pdf_object_ref:n { __hyp/OCG/View }
            \c_space_tl
            \pdf_object_ref:n { __hyp/OCG/Print }
          }
        \pdf_object_write:nnn { __hyp/OCG/View } { dict }
          {
            /Type/OCG
            /Name(View)
            /Usage
             <<
              /Print <</PrintState/OFF>>~
              /View  <</ViewState/ON  >>~
             >>
          }
        \pdf_object_write:nnn { __hyp/OCG/Print } { dict }
          {
            /Type/OCG
            /Name(Print)
            /Usage
             <<
              /Print <</PrintState/ON>>~
              /View  <</ViewState/OFF>>~
             >>
          }
       \pdfmanagement_add:nne { Catalog / OCProperties }{OCGs }{ \pdf_object_ref:n {__hyp/OCG/View} }
       \pdfmanagement_add:nne { Catalog / OCProperties }{OCGs }{ \pdf_object_ref:n {__hyp/OCG/Print} }
       \pdf_object_write:nne { __hyp/OCG/config } { dict }
         {
           /OFF[\pdf_object_ref:n { __hyp/OCG/Print }]
           /AS[
             <<
              /Event/View
              /OCGs\c_space_tl \pdf_object_ref:n { __hyp/OCG/refarray }
              /Category[/View]
             >>
             <<
              /Event/Print
              /OCGs\c_space_tl \pdf_object_ref:n { __hyp/OCG/refarray }
              /Category[/Print]
             >>
             <<
              /Event/Export
              /OCGs\c_space_tl \pdf_object_ref:n { __hyp/OCG/refarray }
              /Category[/Print]
             >>
              ]
         }
       \pdfmanagement_add:nne { Catalog / OCProperties }{ D }{ \pdf_object_ref:n { __hyp/OCG/config} }
       \cs_gset:Npn \__hyp_ocg_init: {}
  }
\prop_map_inline:Nn \c__hyp_map_hyp_annot_prop
  {
     \hook_gput_code:nnn
       {pdfannot/link/#2/begin}
       {hyp/ocg}
       {
         \bool_if:cT { l_hyp_annot_ocgcolor#1_bool }
           {
             \__hyp_ocg_init:
             \group_begin:
             \hbox_set:Nw \l__hyp_tmpa_box
           }
       }
     \hook_gput_code:nnn
       {pdfannot/link/#2/end}
       {hyp/ocg}
       {
         \bool_if:cT { l_hyp_annot_ocgcolor#1_bool }
           {
             \hbox_set_end:
               \mbox
                 {
                   \pdf_bdcobject:nn {OC}{__hyp/OCG/Print}
                   \hbox_overlap_right:n { \box_use:N \l__hyp_tmpa_box }
                   \pdf_emc:
                   \pdf_bdcobject:nn {OC}{__hyp/OCG/View}
                   \group_begin:
                   \color_select:n { hyp/color/#1 }
                   \box_use_drop:N \l__hyp_tmpa_box
                   \group_end:
                   \pdf_emc:
                 }
             \group_end:
           }
       }
  }
\bool_lazy_or:nnTF
  { \pdf_version_compare_p:Nn > {1.4} }
  { \str_if_eq_p:ee{\pdf_version_major:}{-1} }
  {
     \keys_define:nn { hyp }
       {
         ,_ocgcolorlinks .meta:n =
            {
              ocgcolorlink=#1,
              ocgcolorurl=#1,
              ocgcolorfile=#1,
              ocgcolorrun=#1,
              ocgcolormenu=#1
            }
         ,_ocgcolorlinks .default:n = true
       }
  }
  {
    \keys_define:nn { hyp }
      {
        ,_ocgcolorlinks .code:n =
          {
            \msg_warning:nnee
              { hyp }
              { ignore-deprecated-or-unknown-option-in-pdf-version }
              { ocgcolorlinks } { \pdf_version_major:.\pdf_version_minor: }
          }
      }
  }

\keys_define:nn { hyp }
  {
    ,ocgcolorlinks .choice:
    ,ocgcolorlinks / true .meta:n =
      {
        pdfborder      ={0~0~0},
        pdfborderstyle ={},
        colorlinks     = false,
        _ocgcolorlinks = true
      }
    ,ocgcolorlinks / false .meta:n =
      {
        _ocgcolorlinks = false
      }
    ,ocgcolorlinks .default:n = {true}
  }

\seq_map_inline:Nn \c__hyp_annot_types_seq
  {
    \bool_lazy_or:nnTF
      { \pdf_version_compare_p:Nn > {1.4} }
      { \str_if_eq_p:ee{\pdf_version_major:}{-1} }
      {
        \keys_define:nn { hyp }
          {
            ,ocgcolor#1 .bool_set:c = { l_hyp_annot_ocgcolor#1_bool }
          }
      }
      {
        \keys_define:nn { hyp }
          {
            ,ocgcolor#1 .code:n=
              {
                \msg_warning:nnee
                  { hyp }
                  { ignore-deprecated-or-unknown-option-in-pdf-version }
                  { ocgcolor#1 }
                  { \pdf_version_major:.\pdf_version_minor: }
              }
          }
      }
  }
\prop_map_inline:Nn \c__hyp_map_hyp_annot_prop
  {
    \keys_define:nn { hyp }
      {
        ,#1highlight .choices:nn =
          { /I, /N, /O, /P}
          {
                \pdfannot_dict_put:nnn
                  {link/#2}
                  { H }
                  { ##1 }

          }
        ,#1highlight / .code:n =
         {
           \pdfannot_dict_remove:nn
             {link/#2}
             { H }

          }
        ,#1highlight / unknown .code:n =
          {
           \msg_warning:nneee { hyp } { unknown-choice+empty }
             { #1highlight }
             { /I~(inverse), /N~(no effect), /O~(outline), /P~(inset) }
             { \exp_not:n {##1} }
          }
      }
  }

\keys_define:nn { hyp }
  {
    ,pdfhighlight .choices:nn =
      { /I, /N, /O, /P}
      {
        \prop_map_inline:Nn \c__hyp_map_hyp_annot_prop
          {
            \pdfannot_dict_put:nnn
              {link/####2}
              { H }
              { #1  }
          }
      }
    ,pdfhighlight / .code:n =
     {
        \prop_map_inline:Nn \c__hyp_map_hyp_annot_prop
          {
            \pdfannot_dict_remove:nn
              {link/##2}
              { H }
          }
      }
    ,pdfhighlight .initial:n = {/I},
    ,pdfhighlight / unknown .code:n =
      {
       \msg_warning:nneee { hyp } { unknown-choice+empty }
         { pdfhighlight }
         { /I~(inverse), /N~(no effect), /O~(outline), /P~(inset) }
         { \exp_not:n {#1} }
      }
  }
\keys_define:nn { hyp }
  {
    hidelinks .meta:n =
      {
        ,colorlinks    = false
        ,ocgcolorlinks = false
        ,pdfborder     = { 0~0~0 }
        ,pdfborderstyle=
      }
  }

\seq_map_inline:Nn \c__hyp_annot_types_seq
  {
    \keys_define:nn { hyp }
      {
        hide#1 .meta:n =
          {
             ,color#1       = false
             ,ocgcolor#1    = false
             ,#1border      = { 0~0~0 }
             ,#1borderstyle =
          }
      }
  }
\keys_define:nn { hyp }
  {
    colorscheme .code:n =
      {
        \prop_map_inline:cn { c__hyp_colorscheme_#1_prop }
          {
            \keys_set:nn { hyp  }
              {
                 ##1 = ##2
              }
          }
      }
  }
\keys_set:nn { hyp } {colorscheme=phelype}
\keys_define:nn { hyp }
  {
    ,unicode     .code:n = {}
    ,pdfencoding .code:n = {}
    ,pdfversion .code:n =
      {
         \msg_warning:nn { hyp }{ pdfversion-disabled }
      }
   }
\keys_define:nn { hyp }
 {
   ,verbose   .legacy_if_set:n  = {Hy@verbose}
   ,debug     .legacy_if_set:n  = {Hy@verbose}
 }
\keys_define:nn { hyp }
  {
   ,draft .code:n =
     {
       \Hy@drafttrue
       \PassOptionsToPackage{draft}{bookmark}
     }
   ,final .code:n =
     {
       \Hy@finaltrue
       \PassOptionsToPackage{final}{bookmark}
     }
  }
\keys_define:nn { hyp }
 {
   ,extension .tl_set:N = \XR@ext
   ,extension .initial:n= pdf
   ,hypertexnames .legacy_if_set:n = {Hy@hypertexnames}
   ,linkfileprefix .tl_set:N  = \Hy@linkfileprefix
   ,localanchorname .legacy_if_set:n = {Hy@localanchorname}
   ,naturalnames .legacy_if_set:n = {Hy@naturalnames}
   ,pageanchor   .legacy_if_set:n = {Hy@pageanchor}
   ,plainpages   .legacy_if_set:n = {Hy@plainpages}
 }

\keys_define:nn { hyp }
 {
   ,linktoc .choices:nn = { none, section, all, page }
     {
       \cs_set_eq:Nc \Hy@linktoc { Hy@linktoc@#1 }
     }
   ,linktoc / unknown .code:n =
     {
       \msg_warning:nneee { hyp } { unknown-choice }
         { linktoc }
         { none, section, all, page }
         { \exp_not:n {#1} }
     }
   ,linktocpage .choice:
   ,linktocpage / true  .meta:n = {linktoc=page}
   ,linktocpage / false .meta:n = {linktoc=section}
   ,linktocpage .default:n = true
 }

\prop_map_inline:Nn \c__hyp_map_hyp_annot_prop
  {
    \keys_define:nn { hyp }
     {
       ,#1 .bool_set:c = {l__hyp_annot_#2_bool}
     }
  }
\keys_define:nn { hyp }
 {
   ,baseurl       .code:n =
     {
       \__hyp_text_pdfstring:ooN  { #1 } {\l__hyp_text_enc_uri_print_tl} \l__hyp_tmpa_tl
        \tl_if_empty:NTF \l__hyp_tmpa_tl
          {
             \pdfmanagement_remove:nn {Catalog} { URI }
          }
          {
             \pdfmanagement_add:nne {Catalog} { URI }{ <</Base \l__hyp_tmpa_tl>> }
          }
        \__hyp_store_metadata:nn {baseurl}{#1}
     }
   %only false does something ...
   ,bookmarks .choice:
   ,bookmarks / false .code:n = {\RemoveFromHook {begindocument/before}[hyperref/bookmark]}
   ,bookmarks / true .code:n = {}
   ,bookmarks .default:n = {true}
   ,bookmarksnumbered .legacy_if_set:n  = {Hy@bookmarksnumbered}
   ,bookmarksopen .legacy_if_set:n = {Hy@bookmarksopen}
   ,bookmarksopenlevel .tl_set:N = \@bookmarksopenlevel
   ,bookmarkstype .tl_set:N = \Hy@bookmarkstype
   ,pdfcenterwindow    .choice:
   ,pdfcenterwindow / false .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences }{ CenterWindow }
     }
   ,pdfcenterwindow / true .code:n =
     {
       \pdfmanagement_add:nnn {Catalog / ViewerPreferences } { CenterWindow }{ true }
     }
   ,pdfcenterwindow /  .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences }{ CenterWindow }
     }
   ,pdfcenterwindow / unknown .code:n =
     {
       \msg_warning:nnee { hyp } { no-bool }
         { pdfcenterwindow }
         { \exp_not:n {#1} }
     }
   ,pdfcenterwindow    .default:n = true
   ,pdfdirection    .choice:
   ,pdfdirection / L2R .code:n =
     {
       \pdfmanagement_add:nnn {Catalog / ViewerPreferences } { Direction }{ /L2R }
     }
   ,pdfdirection / R2L .code:n =
     {
       \pdfmanagement_add:nnn {Catalog / ViewerPreferences } { Direction }{ /R2L }
     }
   ,pdfdirection /  .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences } { Direction }
     }
   ,pdfdirection / unknown .code:n =
     {
       \msg_warning:nneee { hyp } { unknown-choice+empty }
         { pdfdirection }
         { L2R , R2L }
         { \exp_not:n {#1} }
     }
   ,pdfdisplaydoctitle    .choice:
   ,pdfdisplaydoctitle / false .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences } { DisplayDocTitle }
     }
   ,pdfdisplaydoctitle / true .code:n =
     {
       \pdfmanagement_add:nnn {Catalog / ViewerPreferences } { DisplayDocTitle } { true }
     }
   ,pdfdisplaydoctitle    .default:n = true
   ,pdfduplex    .choices:nn =
     {Simplex, DuplexFlipShortEdge, DuplexFlipLongEdge}
     {
       \pdf_version_compare:NnTF > {1.6}
         {
           \pdfmanagement_add:nnn {Catalog / ViewerPreferences }
             { PrintDuplex } { /#1 }
         }
         {
           \msg_warning:nnee
             {hyp}
             {ignore-deprecated-or-unknown-option-in-pdf-version}
             {pdfduplex}
             {\pdf_version:}
         }
     }%
   ,pdfduplex /  .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences } { PrintDuplex }
     }
   ,pdfduplex / unknown .code:n =
     {
       \msg_warning:nneee { hyp } { unknown-choice+empty }
         { pdfduplex }
         { Simplex, DuplexFlipShortEdge, DuplexFlipLongEdge }
         { \exp_not:n {#1} }
     }
   ,pdffitwindow    .choice:
   ,pdffitwindow / false .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences }  { FitWindow }
     }
   ,pdffitwindow / true .code:n =
     {
       \pdfmanagement_add:nnn {Catalog / ViewerPreferences } { FitWindow } { true }
     }
   ,pdffitwindow /  .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences } { FitWindow }
     }
   ,pdffitwindow    .default:n = true
   ,pdffitwindow / unknown .code:n =
     {
       \msg_warning:nnee { hyp } { no-bool }
         { pdffitwindow }
         { \exp_not:n {#1} }
     }
   ,pdflinkmargin .code:n = { \pdfannot_link_margin:n { #1 } }
   ,pdflinkmargin .initial:n = {1pt}
   ,pdfmenubar    .choice:
   ,pdfmenubar / true .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences } { HideMenubar }
     }
   ,pdfmenubar / false .code:n =
     {
       \pdfmanagement_add:nn {Catalog / ViewerPreferences }
          { HideMenubar } { true }
     }
   ,pdfmenubar /  .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences } { HideMenubar }
     }
   ,pdfmenubar    .default:n = true
   ,pdfmenubar / unknown .code:n =
     {
       \msg_warning:nnee { hyp } { no-bool }
         { pdfmenubar }
         { \exp_not:n {#1} }
     }
   ,pdfnewwindow .choice:
   ,pdfnewwindow / true .code:n =
     {
       \pdfdict_put:nnn {l_hyp/annot/A/GoToR}{/NewWindow}{true}
       \pdfdict_put:nnn {l_hyp/annot/A/Launch}{/NewWindow}{true}
     }
   ,pdfnewwindow / false .code:n =
     {
       \pdfdict_put:nnn {l_hyp/annot/A/GoToR}{/NewWindow}{false}
       \pdfdict_put:nnn {l_hyp/annot/A/Launch}{/NewWindow}{false}
     }
   ,pdfnewwindow /  .code:n =
     {
       \pdfdict_remove:nn {l_hyp/annot/A/GoToR}{/NewWindow}
       \pdfdict_remove:nn {l_hyp/annot/A/Launch}{/NewWindow}
     }
   ,pdfnonfullscreenpagemode   .choices:nn =
     { UseNone, UseOutlines, UseThumbs, FullScreen, UseOC } %pdf 1.5
     {
       \pdfmanagement_add:nne {Catalog / ViewerPreferences }
         { NonFullScreenPageMode} {/#1}
     }
   ,pdfnonfullscreenpagemode / UseAttachments .code:n =
     {
       \pdf_version_compare:NnTF < {1.6}
         {
           %message
         }
         {
           \pdfmanagement_add:nne {Catalog / ViewerPreferences }
             {NonFullScreenPageMode}{/UseAttachments}
         }
     }
   ,pdfnonfullscreenpagemode /  .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences } { NonFullScreenPageMode }
     }
   ,pdfnonfullscreenpagemode / unknown .code:n =
     {
       \msg_warning:nneee { hyp } { unknown-choice+empty }
         { pdfnonfullscreenpagemode }
         { UseNone, UseOutlines, UseThumbs, FullScreen, UseOC, UseAttachments (PDF 1.6) }
         { \exp_not:n {#1} }
     }
   ,pdfnumcopies .code:n =
     {
       \pdf_version_compare:NnTF > {1.6}
         {
           \tl_if_empty:nTF {#1}
             {
               \pdfmanagement_remove:nn {Catalog / ViewerPreferences } { NumCopies }
             }
             {
               \pdfmanagement_add:nne {Catalog / ViewerPreferences }
                 {NumCopies}{#1}
             }
         }
         {
           \msg_warning:nnee
             {hyp}
             {ignore-deprecated-or-unknown-option-in-pdf-version}
             {pdfnumcopies}
             {\pdf_version:}
         }
     }
   ,pdfpagelayout .choices:nn =
     { SinglePage, OneColumn, TwoColumnLeft, TwoColumnRight, TwoPageLeft, TwoPageRight}
     { \pdfmanagement_add:nne {Catalog} { PageLayout }{ /#1 } }
   ,pdfpagelayout / .code:n =
     { \pdfmanagement_remove:nn {Catalog} { PageLayout } }
   ,pdfpagelayout / unknown .code:n =
     {
       \msg_warning:nneee { hyp } { unknown-choice+empty }
         { pdfpagelayout }
         { SinglePage, OneColumn, TwoColumnLeft, TwoColumnRight, TwoPageLeft, TwoPageRight }
         { \exp_not:n {#1} }
     }
   ,pdfpagemode   .choices:nn =
     { UseNone, UseOutlines, UseThumbs, FullScreen, UseOC } %pdf 1.5
     { \pdfmanagement_add:nne {Catalog} { PageMode }{ /#1 } }
   ,pdfpagemode / UseAttachments .code:n =
     {
       \pdf_version_compare:NnTF > {1.5}
         {
           \pdfmanagement_add:nne {Catalog} { PageMode }{ /UseAttachments }
         }
         {
           \msg_warning:nnee
             {hyp}
             {ignore-deprecated-or-unknown-value-in-pdf-version}
             {UseAttachments}
             {\pdf_version:}
         }
     }
   ,pdfpagemode   .initial:n  = { UseOutlines } %for now ...
   ,pdfpagemode / unknown .code:n =
     {
       \msg_warning:nneee { hyp } { unknown-choice+empty }
         { pdfpagemode }
         { UseNone, UseOutlines, UseThumbs, FullScreen, UseOC, UseAttachments (PDF 1.6) }
         { \exp_not:n {#1} }
     }
   ,pdfpagescrop  .code:n =
     {
       \tl_if_empty:nTF {#1} %or blank?
         {
           \pdfmanagement_remove:nn {Pages} { CropBox }
         }
         {
           \pdfmanagement_add:nne {Pages} { CropBox } { [#1] }
         }
     }
   ,pdfpicktraybypdfsize    .choice:
   ,pdfpicktraybypdfsize / true .code:n =
     {
       \pdf_version_compare:NnTF > {1.6}
         {
           \pdfmanagement_add:nnn {Catalog / ViewerPreferences }
             { PickTrayByPDFSize } { true }
         }
         {
           \msg_warning:nnee
             {hyp}
             {ignore-deprecated-or-unknown-option-in-pdf-version}
             {pdfpicktraybypdfsize}
             {\pdf_version:}
         }
     }
   ,pdfpicktraybypdfsize / false .code:n =
     {
       \pdf_version_compare:NnTF > {1.6}
         {
           \pdfmanagement_add:nnn {Catalog / ViewerPreferences }
             { PickTrayByPDFSize } { false }
         }
         {
           \msg_warning:nnee
             {hyp}
             {ignore-deprecated-or-unknown-option-in-pdf-version}
             {pdfpicktraybypdfsize}
             {\pdf_version:}
         }
     }
   ,pdfpicktraybypdfsize /  .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences } { PickTrayByPDFSize }
     }
   ,pdfpicktraybypdfsize / unknown .code:n =
     {
       \msg_warning:nnee { hyp } { no-bool }
         { picktraybypdfsize }
         { \exp_not:n {#1} }
     }
   ,pdfprintarea    .choices:nn =
     { MediaBox, CropBox, BleedBox, TrimBox, ArtBox }
     {
       \pdf_version_compare:NnTF < {2.0}
         {
           \pdfmanagement_add:nne {Catalog / ViewerPreferences }
             { PrintArea } { /#1 }
         }
         {
           \msg_warning:nnee
             {hyp}
             {ignore-deprecated-or-unknown-option-in-pdf-version}
             {pdfprintarea}
             {\pdf_version:}
         }
     }%
   ,pdfprintarea /  .code:n =
     { \pdfmanagement_remove:nn {Catalog / ViewerPreferences } { PrintArea } }
   ,pdfprintarea / unknown .code:n =
     {
       \msg_warning:nneee { hyp } { unknown-choice+empty }
         { pdfprintarea }
         { MediaBox, CropBox, BleedBox, TrimBox, ArtBox }
         { \exp_not:n {#1} }
     }
   ,pdfprintclip    .choices:nn =
     { MediaBox, CropBox, BleedBox, TrimBox, ArtBox }
     {
       \pdf_version_compare:NnTF < {2.0}
         {
           \pdfmanagement_add:nne {Catalog / ViewerPreferences }
             { PrintClip } { /#1 }
         }
         {
           \msg_warning:nnee
             {hyp}
             {ignore-deprecated-or-unknown-option-in-pdf-version}
             {pdfprintclip}
             {\pdf_version:}
         }
     }%
   ,pdfprintclip /  .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences } { PrintClip }
     }
   ,pdfprintclip / unknown .code:n =
     {
       \msg_warning:nneee
         { hyp }
         { unknown-choice+empty }
         { pdfprintclip }
         { MediaBox, CropBox, BleedBox, TrimBox, ArtBox }
         { \exp_not:n {#1} }
     }
   ,pdfprintpagerange .code:n =
     {
       \pdf_version_compare:NnTF > {1.6}
         {
           \tl_if_empty:nTF { #1}
             {
               \pdfmanagement_remove:nn {Catalog / ViewerPreferences }
                 { PrintPageRange }
             }
             {
              \pdfmanagement_add:nne {Catalog / ViewerPreferences }
                 {PrintPageRange}{[#1]}
             }
         }
         {
            \msg_warning:nnee
              {hyp}
              {ignore-deprecated-or-unknown-option-in-pdf-version}
              {pdfprintpagerange}
              {\pdf_version:}
         }
     }
   ,pdfprintscaling    .choices:nn =
     { None, AppDefault }
     {
       \pdf_version_compare:NnTF > {1.5}
         {
           \pdfmanagement_add:nne {Catalog / ViewerPreferences }
             { PrintScaling } { /#1 }
         }
         {
           \msg_warning:nnee
             {hyp}
             {ignore-deprecated-or-unknown-option-in-pdf-version}
             {pdfprintscaling}
             {\pdf_version:}
         }
     }%
   ,pdfprintscaling /  .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences } {PrintScaling }
     }
   ,pdfprintscaling / unknown .code:n =
     {
       \msg_warning:nneee { hyp } { unknown-choice+empty }
         { pdfprintarea }
         { None, AppDefault }
         { \exp_not:n {#1} }
     }
   ,pdfremotestartview .code:n =
     {
       \tl_set:Ne \l__hyp_tmpa_tl {#1~null~null~null~}
       \exp_args:NNV
       \regex_extract_once:NnNTF \c__hyp_dest_startview_regex \l__hyp_tmpa_tl  \l__hyp_tmpa_seq
         {
           \tl_set:Ne \l__hyp_dest_pdfremotestartview_tl {\seq_item:Nn \l__hyp_tmpa_seq {1}}
         }
         {
           \msg_warning:nnnn {hyp}{invalid-destination-value}{#1}{pdfremotestartview}
           \tl_set:Nn \l__hyp_dest_pdfremotestartview_tl {Fit}
         }
     }
   ,pdfremotestartview .initial:n = {Fit}
   % pdfstartpage is special as it shares code with pdfstartview
   ,pdfstartpage .code:n =
     {
       \tl_gset:Ne \g__hyp_dest_pdfstartpage_tl { #1 }
       \bool_if:nTF
         { \tl_if_empty_p:N \g__hyp_dest_pdfstartpage_tl || \tl_if_empty_p:N \g__hyp_dest_pdfstartview_tl }
         {
           \pdfmanagement_remove:nn {Catalog} { OpenAction }
         }
         {
           \pdfmanagement_add:nne {Catalog} { OpenAction }
             {
               [\pdf_pageobject_ref:n {\g__hyp_dest_pdfstartpage_tl}~/\g__hyp_dest_pdfstartview_tl]
             }
         }
     }
   ,pdfstartpage .initial:n =1
   ,pdfstartview .code:n =
     {
       \tl_set:Ne \l__hyp_tmpa_tl {#1~null~null~null~}
       \exp_args:NNV
       \regex_extract_once:NnNTF \c__hyp_dest_startview_regex \l__hyp_tmpa_tl  \l__hyp_tmpa_seq
         {
           \tl_gset:Ne \g__hyp_dest_pdfstartview_tl {\seq_item:Nn \l__hyp_tmpa_seq {1}}
         }
         {
           \msg_warning:nnnn {hyp}{invalid-destination-value}{#1}{pdfstartview}
           \tl_gset:Nn \g__hyp_dest_pdfstartview_tl {Fit}
         }
       \bool_if:nTF
         { \tl_if_empty_p:N \g__hyp_dest_pdfstartpage_tl || \tl_if_empty_p:N \g__hyp_dest_pdfstartview_tl }
         {
           \pdfmanagement_remove:nn {Catalog} { OpenAction }
         }
         {
           \pdfmanagement_add:nne {Catalog} { OpenAction }
             {
               [\pdf_pageobject_ref:n {\g__hyp_dest_pdfstartpage_tl}~/\g__hyp_dest_pdfstartview_tl]
             }
         }
     }
   ,pdfstartview .initial:n = Fit
   ,pdftoolbar    .choice:
   ,pdftoolbar / true .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences } { HideToolbar }
     }
   ,pdftoolbar / false .code:n =
     {
       \pdfmanagement_add:nnn {Catalog / ViewerPreferences }
         { HideToolbar } { true }
     }
   ,pdftoolbar / true .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences } { HideToolbar }
     }
   ,pdftoolbar    .default:n = true
   ,pdftoolbar / unknown .code:n =
     {
       \msg_warning:nnee { hyp } { no-bool }
         { pdftoolbar }
         { \exp_not:n {#1} }
     }
   % pdfview see below.
   ,pdfviewarea    .choices:nn =
     { MediaBox, CropBox, BleedBox, TrimBox, ArtBox }
     {
       \pdf_version_compare:NnTF < {2.0}
         {
           \pdfmanagement_add:nnn {Catalog / ViewerPreferences }
             { ViewArea } { /#1 }
         }
         {
           \msg_warning:nnee
             {hyp}
             {ignore-deprecated-or-unknown-option-in-pdf-version}
             {pdfviewarea}
             {\pdf_version:}
         }
     }%
   ,pdfviewarea /  .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences } { ViewArea }
     }
   ,pdfviewarea / unknown .code:n =
     {
       \msg_warning:nneee { hyp } { unknown-choice+empty }
         { pdfviewarea }
         { MediaBox, CropBox, BleedBox, TrimBox, ArtBox }
         { \exp_not:n {#1} }
     }
   ,pdfviewclip    .choices:nn =
     { MediaBox, CropBox, BleedBox, TrimBox, ArtBox }
     {
       \pdf_version_compare:NnTF < {2.0}
         {
           \pdfmanagement_add:nnn {Catalog / ViewerPreferences }
             { ViewClip } { /#1 }
         }
         {
           \msg_warning:nnee
             {hyp}
             {ignore-deprecated-or-unknown-option-in-pdf-version}
             {pdfviewclip}
             {\pdf_version:}
         }
     }%
   ,pdfviewclip /  .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences } { ViewClip }
     }
   ,pdfviewclip / unknown .code:n =
     {
       \msg_warning:nneee { hyp } { unknown-choice+empty }
         { pdfviewclip }
         { MediaBox, CropBox, BleedBox, TrimBox, ArtBox }
         { \exp_not:n {#1} }
     }
   ,pdfwindowui    .choice:
   ,pdfwindowui / true .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences } { HideWindowUI }
     }
   ,pdfwindowui / false .code:n =
     {
       \pdfmanagement_add:nnn {Catalog / ViewerPreferences }
          { HideWindowUI } { true }
     }
   ,pdfwindowui /  .code:n =
     {
       \pdfmanagement_remove:nn {Catalog / ViewerPreferences } {HideWindowUI }
     }
   ,pdfwindowui / unknown .code:n =
     {
       \msg_warning:nnee { hyp } { no-bool }
         { pdfwindowui }
         { \exp_not:n {#1} }
     }
   ,pdfwindowui    .default:n = true
 }
\keys_define:nn { hyp }
  {
    ,pdfview .code:n =
      {
        \seq_set_split:Nnn \l__hyp_tmpa_seq {~}{#1}
        \str_case_e:nnF { \str_lowercase:f{ \seq_item:Nn \l__hyp_tmpa_seq {1} } }
           {
             { xyz }
               {
                 \int_compare:nNnTF {\seq_count:N \l__hyp_tmpa_seq } > { 1 }
                   {
                     \seq_get_right:NN \l__hyp_tmpa_seq \l__hyp_tmpa_tl
                     \tl_if_eq:NnTF \l__hyp_tmpa_tl {null}
                       {
                         \tl_set:Nn \l__hyp_dest_pdfview_tl {xyz}
                       }
                       {
                         \tl_set:Ne \l__hyp_dest_pdfview_tl
                            {
                               \fp_eval:n { \l__hyp_tmpa_tl * 100 }
                            }
                       }
                   }
                   {
                     \tl_set:Nn \l__hyp_dest_pdfview_tl {xyz}
                   }
               }
             { fit }   { \tl_set:Nn \l__hyp_dest_pdfview_tl {fit}  }
             { fitb }  { \tl_set:Nn \l__hyp_dest_pdfview_tl {fitb} }
             { fitbh } { \tl_set:Nn \l__hyp_dest_pdfview_tl {fitbh}}
             { fitbv } { \tl_set:Nn \l__hyp_dest_pdfview_tl {fitbv}}
             { fith }  { \tl_set:Nn \l__hyp_dest_pdfview_tl {fith} }
             { fitv }  { \tl_set:Nn \l__hyp_dest_pdfview_tl {fitv} }
             { fitr }
               {
                 \int_compare:nNnTF {\seq_count:N \l__hyp_tmpa_seq } = {1}
                   {
                     \tl_set:Nn \l__hyp_dest_pdfview_tl {fitr}
                   }
                   {
                      %ensure 4 values ...
                     \tl_set:Nn \l__hyp_dest_pdfview_tl {fitrbox}
                     \seq_put_right:Nn \l__hyp_tmpa_seq  {0}
                     \seq_put_right:Nn \l__hyp_tmpa_seq  {0}
                     \seq_put_right:Nn \l__hyp_tmpa_seq  {0}
                     \hbox_set_to_wd:Nnn \l__hyp_dest_box
                       {
                         \fp_eval:n
                          {
                            round
                             (
                               abs
                                (
                                  \seq_item:Nn\l__hyp_tmpa_seq{4}
                                  -
                                  (\seq_item:Nn\l__hyp_tmpa_seq{2})
                                 ),
                                3
                             )
                          }bp
                       }{}
                     \box_set_dp:Nn \l__hyp_dest_box
                       {
                         \fp_eval:n
                           {
                             round(0 - (\seq_item:Nn\l__hyp_tmpa_seq{3}),3)
                           }bp
                       }
                     \box_set_ht:Nn \l__hyp_dest_box
                       {
                         \seq_item:Nn\l__hyp_tmpa_seq{5}bp
                       }
                   }
               }
           }
           {
              \msg_warning:nnnn {hyp}{invalid-destination-value}{#1}{pdfview}
              \tl_set:Nn \l__hyp_dest_pdfview_tl {fit}
           }
      }
    ,pdfview .initial:n  = {xyz}
  }
\keys_define:nn { hyp }
  {
   ,pdflang       .code:n =
          {
            \tl_if_empty:nF { #1 }
              {
                \pdfmanagement_add:nne {Catalog} { Lang } { (#1) }
                \AddToDocumentProperties[document]{lang}{#1}
              }
          }
   }
\regex_new:N\l__hyp_optlang_regex
\regex_set:Nn\l__hyp_optlang_regex {\A\[([A-Za-z\-]+)\](.*)}
\cs_generate_variant:Nn\clist_item:nn{on}
\cs_new_protected:Npn \__hyp_setup_info_key:nn #1 #2
  {
    \keys_define:nn { hyp }
      {
        pdf#1  .code:n =
          {
            \tl_set:Ne\l__hyp_tmpa_tl {\text_expand:n{##1}}
            \__hyp_store_metadata:no {pdf#1}{\l__hyp_tmpa_tl}
            \tl_if_empty:NTF \l__hyp_tmpa_tl
              {
                \str_case:nnF { #1 }
                 {
                   {creator}
                   {
                     \msg_info:nnn { hyp }{ empty-info-value } { pdfcreator }
                     \pdfmanagement_add:nne {Info}{Creator}{()}
                   }
                   {producer}
                   {
                     \msg_info:nnn { hyp }{ empty-info-value } { pdfproducer }
                     \pdfmanagement_add:nne {Info}{Producer}{()}
                   }
                 }
                 {
                   \pdfmanagement_remove:nn {Info}{#2}
                 }
              }
              {
                \tl_set:Ne\l__hyp_tmpb_tl {\clist_item:on{\l__hyp_tmpa_tl}{1}}
                \exp_args:NNV
                 \regex_extract_once:NnN \l__hyp_optlang_regex \l__hyp_tmpb_tl\l__hyp_tmpa_seq
                \seq_if_empty:NTF\l__hyp_tmpa_seq
                 {
                   \__hyp_text_pdfstring_info:oN {\l__hyp_tmpa_tl}\l__hyp_tmpa_str
                 }
                 {
                   \__hyp_text_pdfstring_info:eN {\seq_item:Nn \l__hyp_tmpa_seq{3}}\l__hyp_tmpa_str
                 }
                \str_if_eq:VnF\l__hyp_tmpa_str{<FEFF>}
                  {
                    \pdfmanagement_add:nne {Info}{#2}{\l__hyp_tmpa_str}
                  }
              }
          }
      }
    \keys_define:nn { hyp / info }
      {
        #2  .code:n =
          {
            \tl_set:Ne\l__hyp_tmpa_tl {\text_expand:n{##1}}
            \__hyp_store_metadata:eo {pdf\str_lowercase:n{#1}}{\l__hyp_tmpa_tl}
            \tl_if_blank:nTF {##1}
              {
                \pdfmanagement_remove:nn {Info}{#2}
              }
              {
                \__hyp_text_pdfstring_info:oN {\l__hyp_tmpa_tl}\l__hyp_tmpa_str
                \str_if_eq:VnF\l__hyp_tmpa_str{<FEFF>}
                  {
                    \pdfmanagement_add:nne {Info}{#2}{\l__hyp_tmpa_str}
                  }
              }
          }
        ,unknown .code:n =
         {
            \__hyp_text_pdfstring_info:eN {##1}\l__hyp_tmpa_str
            \str_if_eq:VnF\l__hyp_tmpa_str{<FEFF>}
              {
                \exp_args:Nno
                \pdfmanagement_add:nne {Info}
                    { \l_keys_key_str } {\l__hyp_tmpa_str}
              }
         }
      }
  }
\__hyp_setup_info_key:nn {author}   {Author}
\__hyp_setup_info_key:nn {title}    {Title}
\__hyp_setup_info_key:nn {producer} {Producer}
\__hyp_setup_info_key:nn {creator}  {Creator}
\__hyp_setup_info_key:nn {subject}  {Subject}
\__hyp_setup_info_key:nn {keywords}  {Keywords}
\cs_new_protected:Npn \__hyp_setup_info_date_key:nn #1 #2
  {
    \keys_define:nn { hyp }
      {
        pdf#1  .code:n =
          {
            \tl_if_blank:nTF {##1}
              {
                \pdfmanagement_remove:nn {Info}{#2}
              }
              {
                \pdfmanagement_add:nne {Info}{#2}{(##1)}
              }
             \__hyp_store_metadata:nn {pdf#1}{##1}
             \AddToDocumentProperties[document]{#1}{##1}
          }
      }
    \keys_define:nn { hyp / info }
      {
        #2  .code:n =
          {
            \tl_if_blank:nTF {##1}
              {
                \pdfmanagement_remove:nn {Info}{#2}
              }
              {
                \pdfmanagement_add:nne {Info}{#2}{(##1)}
              }
            \exp_args:Ne \__hyp_store_metadata:nn {pdf\str_lowercase:n{#1}}{##1}
          }
      }
  }

\__hyp_setup_info_date_key:nn {creationdate}  {CreationDate}
\__hyp_setup_info_date_key:nn {moddate}  {ModDate}
\keys_define:nn { hyp }
      {
        pdfmetadate  .code:n = { \__hyp_store_metadata:nn {pdfmetadate}{#1} }
      }
\keys_define:nn { hyp }
  {
    ,pdftrapped .code:n =
      {
        \exp_args:Nne
          \keys_set:nn { hyp } { _pdftrapped = \str_uppercase:n { #1 } }
      }
    ,_pdftrapped  .choices:nn = {TRUE,FALSE,UNKNOWN}
       {
         \pdfmanagement_add:nne {Info}{Trapped}
           {/
             \str_uppercase:f { \str_head:n { #1 } }
             \str_lowercase:f { \str_tail:n { #1 } }
           }
         \__hyp_store_metadata:ne {pdftrapped}
           {
             \str_uppercase:f { \str_head:n { #1 } }
             \str_lowercase:f { \str_tail:n { #1 } }
           }
       }
    ,_pdftrapped / unknown .code:n =
       {
         \msg_warning:nneee { hyp } { unknown-choice }
           { pdftrapped }
           { true~(case~insensitive), false~(case~insensitive), unknown~(case~insensitive) }
           { \exp_not:n {#1} }
       }
  }
\keys_define:nn { hyp }
  {
    pdfinfo .code:n =
      {
        \keys_set:nn { hyp / info } { #1 }
      }
  }
\keys_set:nn { hyp} {pdfcreator = LaTeX~with~hyperref}
\keys_set:nn { hyp} {pdfauthor  = }
\keys_set:nn { hyp} {pdftitle   = }
\keys_set:nn { hyp} {pdfsubject  = }
\clist_map_inline:nn
  {
   ,pdfcopyright
   ,pdftype
   ,pdflicenseurl
   ,pdfauthortitle
   ,pdfcaptionwriter
   ,pdfmetalang
   ,pdfsource
   ,pdfdocumentid
   ,pdfinstanceid
   ,pdfversionid
   ,pdfrendition
   ,pdfpublication
   ,pdfpubtype
   ,pdfbytes
   ,pdfnumpages
   ,pdfissn
   ,pdfeissn
   ,pdfisbn
   ,pdfbookedition
   ,pdfpublisher
   ,pdfvolumenum
   ,pdfissuenum
   ,pdfpagerange
   ,pdfdoi
   ,pdfurl
   ,pdfidentifier
   ,pdfsubtitle
   ,pdfpubstatus
   ,pdfcontactaddress
   ,pdfcontactcity
   ,pdfcontactregion
   ,pdfcontactpostcode
   ,pdfcontactcountry
   ,pdfcontactphone
   ,pdfcontactemail
   ,pdfcontacturl
   ,pdfdate
  }
  {
    \keys_define:nn { hyp }
      {
        #1 .code:n= { \__hyp_store_metadata:nn {#1}{##1}}
      }
  }

\keys_define:nn { hyp }
  {
    pdfpageduration .code:n =
     {
        \tl_if_blank:nTF { #1 }
          {
            \pdfmanagement_remove:nn {Page}{Dur}
          }
          {
            \pdfmanagement_add:nnn {Page}{Dur}{#1}
          }
     }
  }
\keys_define:nn { hyp }
  {
    pdfpagetransition .code:n =
     {
       \tl_if_blank:nTF {#1}
         {
           \pdfmanagement_remove:nn {Page}{Trans}
         }
         {
           \group_begin:
           \keys_set:nn { hyp / trans }{style=R,#1}
           \pdf_object_unnamed_write:ne { dict }
             {
               \pdfdict_use:n {l__hyp_page/Trans}
             }
           \pdfmanagement_add:nne {Page}{Trans}{\pdf_object_ref_last:}
           \group_end:
         }
     }
  }
\keys_define:nn { hyp / trans }
  {
    ,style .choices:nn =
      {Split,Blinds,Box,Wipe,Dissolve,Glitter,R,Fly,Push,Cover,Uncover,Fade}
      { \pdfdict_put:nnn {l__hyp_page/Trans}{ S }{/#1} }
    ,style / unknown .code:n =
      {
        \msg_warning:nneee { hyp } { unknown-choice }
           { trans / style }
           { Split,Blinds,Box,Wipe,Dissolve,Glitter,R,Fly,Push,Cover,Uncover,Fade }
           { \exp_not:n {#1} }
      }
    ,duration .code:n  =
      {
        \pdfdict_put:nnn {l__hyp_page/Trans}{ D }{#1}
      }
    ,direction .choices:nn =
      {H,V}
      { \pdfdict_put:nnn {l__hyp_page/Trans}{ Dm }{/#1} }
    ,direction .choices:nn =
      {0,90,180,270,315}
      { \pdfdict_put:nnn {l__hyp_page/Trans}{ Di }{ #1 } }
    ,direction / None .code:n =
      { \pdfdict_put:nnn {l__hyp_page/Trans}{ Di }{ /None } }
    ,direction / unknown .code:n =
      {
        \msg_warning:nneee { hyp } { unknown-choice }
           { trans / direction }
           {
             H~(horizontal,~only~Split,~Blinds),
             V~(vertical,~only~Split,~Blinds),
             0~(left~to~right,~only~Wipe,~Glitter,~Fly,~Cover,~Uncover,~Push),
             90~(bottom~to~top,~only~Wipe),
             180~(right~to~left,~only~Wipe),
             270~(top~to~bottom,~only~Wipe,~Glitter,~Fly,~Cover,~Uncover,~Push),
             315~(top~left~to~bottom,~only~Glitter),
             None~(only~Fly)
           }
           { \exp_not:n {#1} }
      }
    ,motion .choices:nn =
     {I,O}
     { \pdfdict_put:nnn {l__hyp_page/Trans}{ M }{/#1} }
    ,motion / unknown .code:n =
      {
        \msg_warning:nneee { hyp } { unknown-choice }
           { trans / motion }
           { I~(inwards) , O~(outwards) }
           { \exp_not:n {#1} }
      }
     ,scale .code:n =
       { \pdfdict_put:nnn { l__hyp_page/Trans }{ SS }{ #1 } }
     ,opaque .choices:nn = {true,false}
       { \pdfdict_put:nnn { l__hyp_page/Trans }{ B } { #1} }
     ,opaque / unknown .code:n =
       {
          \msg_warning:nneee { hyp } { unknown-choice }
           { trans / B }
           { true~(opaque~back,~only~Fly), false~(opaque~back,~only~Fly) }
           { \exp_not:n {#1} }
       }
     % try to set unknown keys as style
     ,unknown .code:n =
       {
         % warning ...
         \exp_args:Nne\keys_set:nn {hyp/trans}{ style=\l_keys_key_str }
       }
  }
\keys_set_known:nv{ hyp }{opt@hyperref.sty}
%% Form field code
\NewDocumentCommand \MakeFieldObject { m m }
  {
    \pdfxform_new:nnn { #2 }{} { #1 }
  }

\prop_new:N   \g__hyp_AcroForm_CoFields_prop
\prop_new:N   \g__hyp_AcroForm_Fields_prop

\let\HyField@afields\@empty
\let\HyField@cofields\@empty
\def\HyField@AfterAuxOpen{\Hy@AtBeginDocument}%

\def\HyField@AuxAddToFields#1
  {
    \prop_gput:Nnn \g__hyp_AcroForm_Fields_prop {#1}{F}
  }%

\def\HyField@AuxAddToCoFields #1 #2
  {
    \prop_gput:Nnn \g__hyp_AcroForm_CoFields_prop {a#1}{#2}
  }

\Hy@AtBeginDocument
  {
    \if@filesw
      \immediate\write\@mainaux{%
        \string\providecommand\string\HyField@AuxAddToFields[1]{}%
       }%
      \immediate\write\@mainaux{%
        \string\providecommand\string\HyField@AuxAddToCoFields[2]{}%
      }%
    \fi
    \let\HyField@AfterAuxOpen\@firstofone
  }%

\def\HyField@AddToFields
  {
    \exp_args:Ne\HyField__hypAddToFields
      {
        \pdfannot_box_ref_last:
      }
    \ifx\Fld@calculate@code\@empty
    \else
      \begingroup
        \Hy@safe@activestrue
        \edef\Hy@temp{%
          \endgroup
          \if@filesw
            \write\@mainaux
             {
              \string\HyField@AuxAddToCoFields
               {
                \Fld@calculate@sortkey
               }
               {
                 \pdfannot_box_ref_last:
               }
            }
          \fi
        }%
      \Hy@temp
    \fi
  }%

\def\HyField__hypAddToFields#1{
  \HyField@AfterAuxOpen{%
    \if@filesw
      \write\@mainaux{%
        \string\HyField@AuxAddToFields{#1}%
        }%
      \fi
    }%
  }%

\ExplSyntaxOff
\ExplSyntaxOn

\def\@Form[#1]
  {
    \kvsetkeys{Form}{#1}
    \pdf@ifdraftmode{}
      {
        \Hy@FormObjects
        \prop_map_inline:Nn \g__hyp_AcroForm_Fields_prop
          {
            \pdfmanagement_add:nne { Catalog / AcroForm } { Fields }{##1}
            %\pdfmanagement_show:n { Catalog / AcroForm }
          }
        \prop_if_empty:NF \g__hyp_AcroForm_CoFields_prop
          {
            \prop_map_inline:Nn \g__hyp_AcroForm_CoFields_prop
              {
                \seq_put_right:Nn \l__hyp_tmpa_seq {##1}
              }
            \seq_sort:Nn \l__hyp_tmpa_seq
              {
                \str_compare:nNnTF {##1} > {##2}
                  { \sort_return_swapped: }
                  { \sort_return_same: }
              }
            \seq_map_inline:Nn \l__hyp_tmpa_seq
             {
                \pdfmanagement_add:nne { Catalog / AcroForm }
                  { CO }
                  {
                    \prop_item:Nn \g__hyp_AcroForm_CoFields_prop {##1}
                  }
             }
          }
       \pdfmanagement_add:nne {Catalog / AcroForm/DR/Font }
         {ZaDb} {\pdf_object_ref:n {__hyp/Font/ZaDb} }
       \pdfmanagement_add:nne {Catalog / AcroForm/DR/Font }
         {Helv} {\pdf_object_ref:n {__hyp/Font/Helv} }
       \pdfmanagement_add:nne {Catalog /AcroForm}
         {DA}{(/Helv~10~Tf~0~g)}
       \pdfmeta_standard_verify:nTF {form_no_NeedAppearance}
         {
           \legacy_if:nT { HyField@NeedAppearances }
             {
               \pdfmanagement_add:nnn {Catalog / AcroForm }{NeedAppearances}{true}
             }
         }
         {
           \pdfmanagement_remove:nn {Catalog / AcroForm }{NeedAppearances}
         }
       }
  }
\ExplSyntaxOff
\let\@endForm\@empty
\let\HyAnn@AbsPageLabel\@empty
\let\Fld@pageobjref\@empty

\ExplSyntaxOn
\newcount\HyAnn@Count
\HyAnn@Count=\z@
\def\HyAnn@AbsPageLabel
  {
    \global\advance\HyAnn@Count by\@ne
    %\zref@labelbyprops{HyAnn@\the\HyAnn@Count}{abspage}%
    %\zref@labelbylist {HyAnn@\the\HyAnn@Count} {l3pdf}
    %\zref@refused{HyAnn@\the\HyAnn@Count}%
    \__hyp_property_record:ee {HyAnn@\the\HyAnn@Count}{abspage}
    \property_ref_undefined_warn:ee {HyAnn@\the\HyAnn@Count}{abspage}
  }%
\prg_generate_conditional_variant:Nnn \property_if_recorded:nn {ee} {T}
\def\Fld@pageobjref
  {
    \property_if_recorded:eeT {HyAnn@\the\HyAnn@Count}{abspage}
      {
        /P~\pdf_pageobject_ref:e
          {
            \property_ref:ee{HyAnn@\the\HyAnn@Count}{abspage}
          }
      }
  }
\ExplSyntaxOff
\ExplSyntaxOn
%% check if the attr should be set through
%% hooks.
%% check if options are missing.
\def\@TextField[#1]#2{% parameters, label
  \def\Fld@name{#2}%
  \let\Fld@default\@empty
  \let\Fld@value\@empty
  \def\Fld@width{\DefaultWidthofText}%
  \def\Fld@height{%
    \ifFld@multiline
      \DefaultHeightofTextMultiline
    \else
      \DefaultHeightofText
    \fi
  }%
  \begingroup
    \expandafter\HyField@SetKeys\expandafter{%
      \DefaultOptionsofText,#1%
    }%
    \PDFForm@Name
    \HyField@FlagsText
    \ifFld@hidden\def\Fld@width{1sp}\fi
    \ifx\Fld@value\@empty\def\Fld@value{\Fld@default}\fi
    \LayoutTextField{#2}{%
      \leavevmode
      \HyAnn@AbsPageLabel
      \Hy@escapeform\PDFForm@Text
      \pdfannot_box:nnnn
          {\Fld@width}
          {\Fld@height}
          {0pt} %is this correct?
          {\PDFForm@Text}
      \MakeTextField{\Fld@width}{\Fld@height}
      \HyField@AddToFields
    }%
  \endgroup
}
\providecommand\@curropt{}
\def\@ChoiceMenu[#1]#2#3{% parameters, label, choices
  \def\Fld@name{#2}
  \let\Fld@default\relax
  \let\Fld@value\relax
  \def\Fld@width{\DefaultWidthofChoiceMenu}
  \def\Fld@height{\DefaultHeightofChoiceMenu}
  \begingroup
    \Fld@menulength=0 %
    \@tempdima\z@
    \clist_map_variable:nNn { #3 } \@curropt
    %\@for\@curropt:=#3\do
      {%
        \expandafter\Fld@checkequals\@curropt==\\%
        \Hy@StepCount\Fld@menulength
        \settowidth{\@tempdimb}{\@currDisplay}%
        \ifdim\@tempdimb>\@tempdima\@tempdima\@tempdimb\fi
      }%
    \advance\@tempdima by~15\p@
    \begingroup
      \HyField@SetKeys{#1}
    \edef\x{\endgroup
      \noexpand\expandafter
      \noexpand\HyField@SetKeys
      \noexpand\expandafter{%
        \expandafter\noexpand\csname DefaultOptionsof%
          \ifFld@radio
            Radio%
          \else
            \ifFld@combo
              \ifFld@popdown
                PopdownBox%
              \else
                ComboBox%
              \fi
            \else
              ListBox%
            \fi
          \fi
        \endcsname
      }%
    }\x
    \HyField@SetKeys{#1}%
    \PDFForm@Name
    \ifFld@hidden\def\Fld@width{1sp}\fi
    \ifx\Fld@value\relax
      \let\Fld@value\Fld@default
    \fi
    \LayoutChoiceField{#2}{%
      \ifFld@radio
        \HyField@FlagsRadioButton
        \__hypRadio{#3}%
      \else
        \begingroup
          \HyField@FlagsChoice
          \ifdim\Fld@width<\@tempdima
            \ifdim\@tempdima<1cm\@tempdima1cm\fi
            \edef\Fld@width{\the\@tempdima}%
          \fi
          \ifFld@combo
          \else
            \@tempdima=\the\Fld@menulength\Fld@charsize
            \advance\@tempdima by~\Fld@borderwidth bp %
            \advance\@tempdima by~\Fld@borderwidth bp %
            \edef\Fld@height{\the\@tempdima}%
          \fi
          \__hypListbox{#3}%
        \endgroup
      \fi
    }%
  \endgroup
}

\def\__hypRadio#1{%
  \Fld@listcount=0~%
  %\show\Fld@default
  \EdefEscapeName\Fld@default{\Fld@default}%
  \clist_map_variable:nNn { #1 } \@curropt
  %\@for\@curropt:=#1\do
   {%
    \expandafter\Fld@checkequals\@curropt==\\%
    \EdefEscapeName\@currValue{\@currValue}%
    \Hy@StepCount\Fld@listcount
    \@currDisplay\space
    \leavevmode
    \HyAnn@AbsPageLabel
    \Hy@escapeform\PDFForm@Radio
    \pdfxform_if_exist:nF { __hyp_xform_Ding }
      {
        \pdfxform_new:nnn { __hyp_xform_Ding } {}
         {
           \group_begin:
           \fontfamily{pzd}
           \fontencoding{U}
           \fontseries{m}
           \fontshape{n}
           \selectfont
           \char123
           \group_end:
         }
      }
    \pdfannot_box:nnne
      {\Fld@width}
      {\Fld@height}
      {0pt} %is this correct?
      {
        \PDFForm@Radio
        /AP
         <<
         /N
          <<
          /\@currValue\c_space_tl \pdfxform_ref:n {__hyp_xform_Ding}
          %/Off \c_space_tl \pdfxform_ref:n {__hyp_xform_DingOff} %hm
          >>
         >>
      }
      {\fbox{  \MakeRadioField{\Fld@width}{\Fld@height}} }
     \int_compare:nNnT { \Fld@listcount} = { 1 }
      { \HyField@AddToFields }
    \c_space_tl % deliberate space between radio buttons
                % to do: --> should be configurable
  }%
}

\newcount\Fld@listcount
\def\__hypListbox#1
 {
  \HyField@PDFChoices{#1}
  \mode_leave_vertical:
  \HyAnn@AbsPageLabel
  \Hy@escapeform\PDFForm@List
  \pdf_link_user:nnn
       {widget} %perhaps we need more types??
       {\PDFForm@List}
       {\MakeChoiceField{\Fld@width}{\Fld@height}}
  \HyField@AddToFields
 }

\def\@PushButton[#1]#2{% parameters, label
  \def\Fld@name{#2}%
  \group_begin:
    \exp_args:No\HyField@SetKeys
     {
      \DefaultOptionsofPushButton,#1
     }
    \PDFForm@Name
    \pdfmeta_standard_verify:nnTF {annot_action_A}{JavaScript}
      {
        \HyField@FlagsPushButton
        \legacy_if:nT {Fld@hidden}
          {
            \def\Fld@width{1sp}
          }
        \LayoutPushButtonField
          {
            \mode_leave_vertical:
            \HyAnn@AbsPageLabel
            \Hy@escapeform\PDFForm@Push
            \hbox_set:Nn \l_tmpa_box { \MakeButtonField {#2}}
            \pdfannot_box:nnnn
              {\box_wd:N\l_tmpa_box}
              {\box_ht:N\l_tmpa_box}
              {\box_dp:N\l_tmpa_box} %is this correct?
              {\PDFForm@Push}
             {\box_use:N\l_tmpa_box}
            \HyField@AddToFields
          }
      }
      {
        \msg_error:nn { hyp }{ pdfa-no-push-button }
        \LayoutPushButtonField
          {
            \mode_leave_vertical:
            \MakeButtonField{#2}
          }
      }
  \group_end:
}

\def\@Submit[#1]#2
 {
   \def\Fld@width {\DefaultWidthofSubmit}
   \def\Fld@height{\DefaultHeightofSubmit}
   \group_begin:
     \exp_args:No\HyField@SetKeys
       {
         \DefaultOptionsofSubmit,#1
       }
   \HyField@FlagsPushButton
   \HyField@FlagsSubmit
   \legacy_if:nT { Fld@hidden }
     {
       \def\Fld@width{1sp}
     }
    \mode_leave_vertical:
    \HyAnn@AbsPageLabel
    \Hy@escapeform\PDFForm@Submit
    \hbox_set:Nn \l_tmpa_box { \MakeButtonField {#2}}
    \pdfxform_if_exist:nF
     { __hyp_xform_Submit }
     {
       \pdfxform_new:nnn { __hyp_xform_Submit }{}
        {
          \fbox{\color_select:n{yellow}\textsf{Submit}}
        }
       \pdfxform_new:nnn { __hyp_xform_SubmitP }{}
        {
          \fbox{\color_select:n{yellow}\textsf{SubmitP}}
        }
     }
    \pdfannot_box:nnnn
      {\box_wd:N\l_tmpa_box}
      {\box_ht:N\l_tmpa_box}
      {\box_dp:N\l_tmpa_box} %is this correct?
      {
        \PDFForm@Submit
        /AP<<
          /N~\pdfxform_ref:n {__hyp_xform_Submit}~
          /D~\pdfxform_ref:n {__hyp_xform_SubmitP}
         >>
       }
      \HyField@AddToFields
      \box_use:N\l_tmpa_box

    \group_end:
 }

\def\@Reset[#1]#2
 {
   \def\Fld@width {\DefaultWidthofReset}
   \def\Fld@height{\DefaultHeightofReset}
   \group_begin:
     \exp_args:No\HyField@SetKeys
       {
         \DefaultOptionsofReset,#1
       }
     \mode_leave_vertical:
     \pdfmeta_standard_verify:nnTF {annot_action_A}{ResetForm}
       {
         \HyField@FlagsPushButton
         \legacy_if:nT { Fld@hidden }
           { \def\Fld@width{1sp} }
         \HyAnn@AbsPageLabel
         \Hy@escapeform\PDFForm@Reset
         \hbox_set:Nn \l_tmpa_box { \MakeButtonField {#2}}
         \pdfannot_box:nnnn
           {\box_wd:N\l_tmpa_box}
           {\box_ht:N\l_tmpa_box}
           {\box_dp:N\l_tmpa_box} %is this correct?
           { \PDFForm@Reset }
         \HyField@AddToFields
         \box_use:N \l_tmpa_box
       }
       {
         \msg_error:nn { hyp }{ pdfa-no-reset-button }
         \MakeButtonField{#2}
       }
    \group_end:
  }

\def\@CheckBox[#1]#2
  {% parameters, label
    \def\Fld@name{#2}
    \def\Fld@default{0}
    \group_begin:
      \def\Fld@width {\DefaultWidthofCheckBox}
      \def\Fld@height{\DefaultHeightofCheckBox}
      \exp_args:No\HyField@SetKeys
        {
          \DefaultOptionsofCheckBox,#1
        }
      \PDFForm@Name
      \HyField@FlagsCheckBox
      \legacy_if:nT { Fld@hidden }
        {
          \def\Fld@width{1sp}
        }
      \LayoutCheckField{#2}
        {
          \mode_leave_vertical:
          \HyAnn@AbsPageLabel
          \Hy@escapeform\PDFForm@Check
          \pdfxform_if_exist:nF { __hyp_xform_CheckMarkYes }
             {
               \pdfxform_new:nnn
                {__hyp_xform_CheckMarkYes}{}
                {
                  \group_begin:
                  \fontfamily{pzd}
                  \fontencoding{U}
                  \fontseries{m}
                  \fontshape{n}
                  \selectfont
                  \char51
                  \group_end:
                }
               \pdfxform_new:nnn
                {__hyp_xform_CheckMarkOff}{}
                {
                  \group_begin:
                  \fontfamily{pzd}
                  \fontencoding{U}
                  \fontseries{m}
                  \fontshape{n}
                  \selectfont
                  \phantom{\char51} %perhaps xetex needs some small glyph ..
                  \group_end:
                }
             }
          \pdfannot_box:nnnn
            {\Fld@width}
            {\Fld@height}
            {0pt} %is this correct?
            {\PDFForm@Check}
          \HyField@AddToFields %check if this works with xelatex ...
        }
    \group_end:
  }
\ExplSyntaxOff

\ExplSyntaxOn
\def\Hy@FormObjects
  {
    \pdf_object_new:n   {__hyp/Encoding/pdfdoc }
    \pdf_object_new:n   {__hyp/Font/ZaDb }
    \pdf_object_new:n   {__hyp/Font/Helv }
    \pdf_object_write:nne {__hyp/Encoding/pdfdoc } { dict }
      {
        /Type/Encoding
        /Differences[
          24/breve/caron/circumflex/dotaccent/hungarumlaut/ogonek
          /ring/tilde
          \c_space_tl
          39/quotesingle
          \c_space_tl
          96/grave %
          \iow_newline:
          128/bullet/dagger/daggerdbl/ellipsis/emdash/endash/florin
          /fraction/guilsinglleft/guilsinglright/minus/perthousand
          /quotedblbase/quotedblleft/quotedblright/quoteleft
          /quoteright/quotesinglbase/trademark/fi/fl/Lslash/OE
          /Scaron/Ydieresis/Zcaron/dotlessi/lslash/oe/scaron/zcaron
          \iow_newline:
          164/currency
          \c_space_tl
          166/brokenbar
          \c_space_tl
          168/dieresis/copyright/ordfeminine
          \c_space_tl
          172/logicalnot/.notdef/registered/macron/degree/plusminus
          /twosuperior/threesuperior/acute/mu
          \c_space_tl
          183/periodcentered/cedilla/onesuperior/ordmasculine
          \c_space_tl
          188/onequarter/onehalf/threequarters
          \iow_newline:
          192/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE
          /Ccedilla/Egrave/Eacute/Ecircumflex/Edieresis/Igrave
          /Iacute/Icircumflex/Idieresis/Eth/Ntilde/Ograve/Oacute
          /Ocircumflex/Otilde/Odieresis/multiply/Oslash/Ugrave
          /Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls
          /agrave/aacute/acircumflex/atilde/adieresis/aring/ae
          /ccedilla/egrave/eacute/ecircumflex/edieresis/igrave
          /iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute
          /ocircumflex/otilde/odieresis/divide/oslash/ugrave
          /uacute/ucircumflex/udieresis/yacute/thorn/ydieresis
         ]
      }
    \pdf_object_write:nnn {__hyp/Font/ZaDb } { dict }
      {
        /Type/Font
        /Subtype/Type1
        /Name/ZaDb
        /BaseFont/ZapfDingbats
      }
    \pdf_object_write:nne {__hyp/Font/Helv } { dict }
      {
        /Type/Font
        /Subtype/Type1
        /Name/Helv
        /BaseFont/Helvetica
        /Encoding~\pdf_object_ref:n { __hyp/Encoding/pdfdoc }
      }
  \global\let\Hy@FormObjects\relax
  }
\ExplSyntaxOff
\providecommand*{\Fld@pageobjref}{}
\ifcsname pdf@escapestring\endcsname
  \def\Hy@escapeform#1{%
    \ifHy@pdfescapeform
      \let\Hy@escapestring\pdfescapestring
    \else
      \let\Hy@escapestring\@firstofone
    \fi
  }%
  \Hy@escapeform{}%
\else
  \let\Hy@escapestring\@firstofone
  \def\Hy@escapeform#1{%
    \ifHy@pdfescapeform
      \def\Hy@escapestring##1{%
        \noexpand\Hy@escapestring{\noexpand##1}%
      }%
      \edef\Hy@temp{#1}%
      \expandafter\Hy__hypescapeform\Hy@temp\Hy@escapestring{}\@nil
      \def\Hy@escapestring##1{%
        \@ifundefined{Hy@esc@\string##1}{%
          ##1%
          \ThisShouldNotHappen
        }{%
          \csname Hy@esc@\string##1\endcsname
        }%
      }%
    \else
      \let\Hy@escapestring\@firstofone
    \fi
  }%
  \def\Hy__hypescapeform#1\Hy@escapestring#2#3\@nil{%
    \ifx\\#3\\%
    \else
      \expandafter
      \Hy@pstringdef\csname Hy@esc@\string#2\endcsname{#2}% probably string-hex
      \Hy@ReturnAfterFi{%
        \Hy__hypescapeform#3\@nil
      }%
    \fi
  }%
\fi
\def\PDFForm@Name{%
  \PDFForm__hypName\Fld@name
  \ifx\Fld@altname\relax
  \else
    \PDFForm__hypName\Fld@altname
  \fi
  \ifx\Fld@mappingname\relax
  \else
    \PDFForm__hypName\Fld@mappingname
  \fi
}
\def\PDFForm__hypName#1{%
  \begingroup
    \ifnum\Hy@pdfversion<5 % implementation note 117, PDF spec 1.7
      \ifHy@unicode
        \Hy@unicodefalse
      \fi
    \fi
    \pdfstringdef\Hy@gtemp#1%
  \endgroup
  \let#1\Hy@gtemp
}
\def\Fld@X@additionalactions{%
  \ifx\Fld@keystroke@code\@empty
  \else
    /K<</S/JavaScript/JS(\Hy@escapestring{\Fld@keystroke@code})>>%
  \fi
  \ifx\Fld@format@code\@empty
  \else
    /F<</S/JavaScript/JS(\Hy@escapestring{\Fld@format@code})>>%
  \fi
  \ifx\Fld@validate@code\@empty
  \else
    /V<</S/JavaScript/JS(\Hy@escapestring{\Fld@validate@code})>>%
  \fi
  \ifx\Fld@calculate@code\@empty
  \else
    /C<</S/JavaScript/JS(\Hy@escapestring{\Fld@calculate@code})>>%
  \fi
  \ifx\Fld@onfocus@code\@empty
  \else
    /Fo<</S/JavaScript/JS(\Hy@escapestring{\Fld@onfocus@code})>>%
  \fi
  \ifx\Fld@onblur@code\@empty
  \else
    /Bl<</S/JavaScript/JS(\Hy@escapestring{\Fld@onblur@code})>>%
  \fi
  \ifx\Fld@onmousedown@code\@empty
  \else
    /D<</S/JavaScript/JS(\Hy@escapestring{\Fld@onmousedown@code})>>%
  \fi
  \ifx\Fld@onmouseup@code\@empty
  \else
    /U<</S/JavaScript/JS(\Hy@escapestring{\Fld@onmouseup@code})>>%
  \fi
  \ifx\Fld@onenter@code\@empty
  \else
    /E<</S/JavaScript/JS(\Hy@escapestring{\Fld@onenter@code})>>%
  \fi
  \ifx\Fld@onexit@code\@empty
  \else
    /X<</S/JavaScript/JS(\Hy@escapestring{\Fld@onexit@code})>>%
  \fi
}
\ExplSyntaxOn
\def\Fld@additionalactions
 {%
  \exp_args:Ne\str_if_eq:nnF {\Fld@X@additionalactions}{}
    {
      \pdfmeta_standard_verify:nT {annot_widget_no_AA}
        {/AA<<\Fld@X@additionalactions>>}
    }
 }
\ExplSyntaxOff
\def\Fld@annotnames{%
  /T(\Fld@name)%
  \ifx\Fld@altname\relax
  \else
    /TU(\Fld@altname)%
  \fi
  \ifx\Fld@mappingname\relax
  \else
    /TM(\Fld@mappingname)%
  \fi
}
\ExplSyntaxOn
\def\PDFForm@Check
  {
    /Subtype/Widget
    ~\Fld@annotflags
    ~\Fld@pageobjref
    ~\Fld@annotnames
    /FT/Btn
   \Fld@flags
   /Q~\Fld@align
   /BS<</W~\Fld@borderwidth /S/\Fld@borderstyle>>
   /AP
     <<
      /N
        <<
          /Yes~\pdfxform_ref:n{__hyp_xform_CheckMarkYes}
          /Off~\pdfxform_ref:n{__hyp_xform_CheckMarkOff}
        >>
    >>
  /MK<<
    \int_compare:nNnF {\Fld@rotation}={0}
      {
        /R~\Fld@rotation
      }
    \tl_if_empty:NF\Fld@bordercolor
      {
        /BC[\Fld@bordercolor]
      }
    \tl_if_empty:NF\Fld@bcolor
      {
        /BG[\Fld@bcolor]
      }
    /CA(\Hy@escapestring{\Fld@cbsymbol})%
  >>
  /DA
    (
      /ZaDb~\strip@pt\Fld@charsize\c_space_tl Tf
      \tl_if_empty:NF \Fld@color
        {
          \c_space_tl \Fld@color
        }
    )
  /H/P
  \legacy_if:nTF {Fld@checked}
    {
      /V/Yes /AS/Yes
    }
    {
      /V/Off /AS/Off
    }
  \Fld@additionalactions
}
\ExplSyntaxOff
\ExplSyntaxOn
   \def\PDFForm@Push
     {
       /Subtype/Widget
       ~\Fld@annotflags
       ~\Fld@pageobjref
       ~\Fld@annotnames
       /FT/Btn
       ~\Fld@flags
       /H/P
       /BS<</W~\Fld@borderwidth/S/\Fld@borderstyle>>
       \bool_if:nT
         {
           !\int_compare_p:nNn {\Fld@rotation} = {0}
          ||
           \tl_if_exist_p:N \Fld@bordercolor
         }
         {
           /MK
             <<
               \int_compare:nNnF {\Fld@rotation} = {0}
                 {
                   /R~\Fld@rotation
                 }
               \tl_if_exist:NT \Fld@bordercolor
                 {
                   /BC[\Fld@bordercolor]
                 }
             >>
          }
       /A<</S/JavaScript/JS(\Hy@escapestring{\Fld@onclick@code})>>
       \Fld@additionalactions
     }

\ExplSyntaxOff
\def\PDFForm@List{%
  /Subtype/Widget%
  \Fld@annotflags
  \Fld@pageobjref
  \Fld@annotnames
  /FT/Ch%
  \Fld@flags
  /Q \Fld@align
  /BS<</W \Fld@borderwidth/S/\Fld@borderstyle>>%
  \ifcase0\ifnum\Fld@rotation=\z@   \else 1\fi
          \ifx\Fld@bordercolor\relax\else 1\fi
          \ifx\fld@bcolor\relax     \else 1\fi
          \space
  \else
    /MK<<%
      \ifnum\Fld@rotation=\z@
      \else
        /R \Fld@rotation
      \fi
      \ifx\Fld@bordercolor\relax
      \else
        /BC[\Fld@bordercolor]%
      \fi
      \ifx\Fld@bcolor\relax
      \else
        /BG[\Fld@bcolor]%
      \fi
    >>%
  \fi
  /DA(/Helv \strip@pt\Fld@charsize\space Tf%
      \ifx\Fld@color\@empty\else\space\Fld@color\fi)%
  \Fld@choices
  \Fld@additionalactions
}
\ExplSyntaxOn
\def\PDFForm@Radio
  {
    /Subtype/Widget
    ~\Fld@annotflags
    ~\Fld@pageobjref
    ~\Fld@annotnames
    /FT/Btn
   \Fld@flags
   /H/P
   /BS<</W~\Fld@borderwidth/S/\Fld@borderstyle>>
   /MK<<
    \ifnum\Fld@rotation=\z@
    \else
      /R~\Fld@rotation
    \fi
    \ifx\Fld@bordercolor\relax
    \else
      /BC[\Fld@bordercolor]%
    \fi
    \ifx\Fld@bcolor\relax
    \else
      /BG[\Fld@bcolor]%
    \fi
     /CA(\Hy@escapestring{\Fld@radiosymbol})%
    >>
    /DA(/ZaDb~\strip@pt\Fld@charsize\space Tf%
      \ifx\Fld@color\@empty\else\space\Fld@color\fi)%
   \ifx\Fld@default\@empty
    /V/Off%
    /DV/Off%
   \else
    /V/\Fld@default
    /DV/\Fld@default
   \fi
   \Fld@additionalactions
 }
\ExplSyntaxOff
\ExplSyntaxOn
\def\PDFForm@Text
  {
    /Subtype/Widget
    ~\Fld@annotflags
    ~\Fld@pageobjref
    ~\Fld@annotnames
    /FT/Tx
    ~\Fld@flags
    /Q~\Fld@align
    /BS<</W~\Fld@borderwidth\c_space_tl /S /\Fld@borderstyle>>
   \bool_if:nT
     {
        !\int_compare_p:nNn {\Fld@rotation} = {0}
       ||
        \tl_if_exist_p:N \Fld@bordercolor
       ||
        \tl_if_exist_p:N \Fld@bcolor
     }
     {
       /MK
         <<
           \int_compare:nNnF {\Fld@rotation} = {0}
             {
               /R~\Fld@rotation
             }
           \tl_if_exist:NT \Fld@bordercolor
             {
               /BC[\Fld@bordercolor]
             }
           \tl_if_exist:NT \Fld@bcolor
             {
               /BG[\Fld@bcolor]
             }
        >>
     }
   /DA
     (
       /Helv~\strip@pt\Fld@charsize\c_space_tl Tf
       \tl_if_empty:NF {\c_space_tl\Fld@color}
     )
   /DV(\Hy@escapestring{\Fld@default})
   /V(\Hy@escapestring{\Fld@value})
   ~\Fld@additionalactions
   \int_compare:nNnT { \Fld@maxlen}>{0}
     {
       /MaxLen~\Fld@maxlen
     }
  }
\ExplSyntaxOff

\def\PDFForm@Submit{%
  /Subtype/Widget%
  \Fld@annotflags
  \Fld@pageobjref
  \Fld@annotnames
  /FT/Btn%
  \Fld@flags
  /H/P%
  /BS<</W \Fld@borderwidth/S/\Fld@borderstyle>>%
  \ifcase0\ifnum\Fld@rotation=\z@   \else 1\fi
          \ifx\Fld@bordercolor\relax\else 1\fi
          \space
  \else
    /MK<<%
      \ifnum\Fld@rotation=\z@
      \else
        /R \Fld@rotation
      \fi
      \ifx\Fld@bordercolor\relax
      \else
        /BC[\Fld@bordercolor]%
      \fi
    >>%
  \fi
  /A<<%
    /S/SubmitForm%
    /F<<%
      /FS/URL%
      /F(\Hy@escapestring{\Form@action})%
    >>%
    \Fld@submitflags
  >>%
  \Fld@additionalactions
}
\ExplSyntaxOn
       \def\PDFForm@Reset{%
         /Subtype/Widget%
         \Fld@annotflags
         \Fld@pageobjref
         \Fld@annotnames
         /FT/Btn%
         \Fld@flags
         /H/P%
         /DA(/Helv~\strip@pt\Fld@charsize\space Tf~0~0~1~rg)%
         \ifcase0\ifnum\Fld@rotation=\z@   \else 1\fi
                 \ifx\Fld@bordercolor\relax\else 1\fi
                 \space
         \else
           /MK<<%
             \ifnum\Fld@rotation=\z@
             \else
               /R~\Fld@rotation
             \fi
             \ifx\Fld@bordercolor\relax
             \else
               /BC[\Fld@bordercolor]%
             \fi
           >>%
         \fi
         /BS<</W \Fld@borderwidth/S/\Fld@borderstyle>>%
         /A<</S/ResetForm>>%
         \Fld@additionalactions
       }%

 %these patterns are used in hyperref checks.
\str_case:VnF \c_sys_backend_str
 {
   { pdfmode }
   {
     \def\HyPat@ObjRef
      {
       [0-9]*[1-9][0-9]*~0~R
      }
   }
   { dvipdfmx }
   {
     \def\HyPat@ObjRef
      {
        @[^~]+
      }
   }
   { xdvipdfmx }
   {
     \def\HyPat@ObjRef
      {
        @[^~]+
      }
   }
 }
 { %also set in hyperref sty, so probably not needed.
   \def\HyPat@ObjRef/{.+}
 }

\ExplSyntaxOff
%% \RequirePackage{rerunfilecheck}[2009/12/10]
%% removed \Hy@OutlineRerunCheck, unneeded with bookmark
%% removed \ReadBookmarks / unneeded with bookmark.
%% removed \Hy@OutlineName
%% removed \check@bm@number
%% removed \calc@bm@number

\ifHy@implicit
\else
  \expandafter\endinput
\fi
\newlength\Hy@SectionHShift
\def\Hy@SectionAnchorHref#1{%
  \ifx\protect\@typeset@protect
    \Hy__hypSectionAnchor{#1}%
  \fi
}
\DeclareRobustCommand*{\Hy__hypSectionAnchor}[1]{%
  \leavevmode
  \hbox to 0pt{%
    \kern-\Hy@SectionHShift
    \Hy@raisedlink{%
      \hyper@anchorstart{#1}\hyper@anchorend
    }%
    \hss
  }%
}
\@ifundefined{hyper@nopatch@sectioning}
{
\let\H@old@ssect\@ssect
\def\@ssect#1#2#3#4#5{%
  \Hy@MakeCurrentHrefAuto{section*}%
  \setlength{\Hy@SectionHShift}{#1}%
  \begingroup
    \toks@{\H@old@ssect{#1}{#2}{#3}{#4}}%
    \toks\tw@\expandafter{%
      \expandafter\Hy@SectionAnchorHref\expandafter{\@currentHref}%
      #5%
    }%
  \edef\x{\endgroup
    \the\toks@{\the\toks\tw@}%
  }\x
}
\let\H@old@schapter\@schapter
\def\@schapter#1{%
  \begingroup
    \let\@mkboth\@gobbletwo
    \Hy@MakeCurrentHrefAuto{\Hy@chapapp*}%
    \Hy@raisedlink{%
      \hyper@anchorstart{\@currentHref}\hyper@anchorend
    }%
  \endgroup
  \H@old@schapter{#1}%
}
\@ifundefined{@chapter}{}{%
  \let\Hy@org@chapter\@chapter
  \def\@chapter{%
    \def\Hy@next{%
      \Hy@MakeCurrentHrefAuto{\Hy@chapapp*}%
      \Hy@raisedlink{%
        \hyper@anchorstart{\@currentHref}\hyper@anchorend
      }%
    }%
    \ifnum\c@secnumdepth>\m@ne
      \@ifundefined{if@mainmatter}%
      \iftrue{\csname if@mainmatter\endcsname}%
        \let\Hy@next\relax
      \fi
    \fi
    \Hy@next
    \Hy@org@chapter
  }%
}
\let\H@old@part\@part
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname chapter\endcsname\relax
  \let\Hy@secnum@part\z@
\else
  \let\Hy@secnum@part\m@ne
\fi
\def\@part{%
  \ifnum\Hy@secnum@part>\c@secnumdepth
    \phantomsection
  \fi
  \H@old@part
}
\let\H@old@spart\@spart
\def\@spart#1{%
  \Hy@MakeCurrentHrefAuto{part*}%
  \Hy@raisedlink{%
    \hyper@anchorstart{\@currentHref}\hyper@anchorend
  }%
  \H@old@spart{#1}%
}
\let\H@old@sect\@sect
\def\@sect#1#2#3#4#5#6[#7]#8{%
  \ifnum #2>\c@secnumdepth
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
  {%
    \Hy@MakeCurrentHrefAuto{section*}%
    \setlength{\Hy@SectionHShift}{#3}%
    \begingroup
      \toks@{\H@old@sect{#1}{#2}{#3}{#4}{#5}{#6}[{#7}]}%
      \toks\tw@\expandafter{%
        \expandafter\Hy@SectionAnchorHref\expandafter{\@currentHref}%
        #8%
      }%
    \edef\x{\endgroup
      \the\toks@{\the\toks\tw@}%
    }\x
  }{%
    \H@old@sect{#1}{#2}{#3}{#4}{#5}{#6}[{#7}]{#8}%
  }%
}
}{}
\expandafter\def\csname Parent-4\endcsname{}
\expandafter\def\csname Parent-3\endcsname{}
\expandafter\def\csname Parent-2\endcsname{}
\expandafter\def\csname Parent-1\endcsname{}
\expandafter\def\csname Parent0\endcsname{}
\expandafter\def\csname Parent1\endcsname{}
\expandafter\def\csname Parent2\endcsname{}
\expandafter\def\csname Parent3\endcsname{}
\expandafter\def\csname Parent4\endcsname{}
%%
%% End of file 'hgeneric-testphase.def'.
%% 
%%
%% End of file `hgeneric-testphase.def'.
