%D \module
%D   [       file=type-ini,
%D        version=2001.03.05,
%D          title=\CONTEXT\ Typescript Macros,
%D       subtitle=Initialization,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Typescript Macros / Initialization}

\registerctxluafile{type-ini}{autosuffix}

%D The default fontclass is empty. We could demand always using fontclasses, and
%D then make the calling macros simplier (always assume fontclass) but apart from
%D downward compatibility issues, it would make global, class spanning definitions a
%D pain. Some day we will introduce a default class.
%D
%D The \type {type-ini} and \type {font-ini} modules come as a pair and have mutual
%D dependencies.
%D
%D At some point we will only store in memory so some code can go away.

\unprotect

\newinteger    \c_font_typescripts_n_of_preloaded
\newconditional\c_font_typescripts_quit
\newtoks       \c_font_typescripts_document
\newconditional\c_font_typescripts_preload
\newconditional\c_font_typescripts_first_pass          \c_font_typescripts_first_pass\conditionaltrue

\newif         \iftypescriptfound              % will become a mode
\newif         \iftracetypescripts

\newtoks       \everybeforedefinetypeface
\newtoks       \everyafterdefinetypeface

\mutable\lettonothing\typescriptfiles
\mutable\lettonothing\currenttypescripts
\mutable\lettonothing\currenttypefile

\installmacrostack\currenttypefile

\mutable\lettonothing\typescriptone   % public, used in typescripts
\mutable\lettonothing\typescripttwo   % public, used in typescripts
\mutable\lettonothing\typescriptthree % public, used in typescripts

\installmacrostack\typescriptone
\installmacrostack\typescripttwo
\installmacrostack\typescriptthree

\mutable\lettonothing\fontclassstyle

\installmacrostack\fontclassstyle

\lettonothing\m_font_typescripts_one
\lettonothing\m_font_typescripts_two
\lettonothing\m_font_typescripts_three
\lettonothing\m_font_typescripts_check
\lettonothing\m_font_typescripts_match

\installmacrostack\m_font_typescripts_one
\installmacrostack\m_font_typescripts_two
\installmacrostack\m_font_typescripts_three

\mutable\let\t_font_typescripts\relax % uses as synonym

\installcorenamespace{typescriptcache}
\installcorenamespace{typescriptfiles}
\installcorenamespace{typescriptonce}
\installcorenamespace{typescriptsynonyms}
\installcorenamespace{typescriptprefix}
\installcorenamespace{typescriptinheritances}
\installcorenamespace{typescriptdefaultstyles}
\installcorenamespace{typescriptrelatives}

\definesystemvariable{ts} % TypeScript

% tricky ... here we push/pop ... so \let

\mutable\let\typescriptmethod\plusone % 1: empty==all==true  2: empty==false
\mutable\let\typescriptstate \plustwo % 1: process 2: store

\installmacrostack\typescriptmethod
\installmacrostack\typescriptstate

%D When these are loaded it is possible to get spaces but the whole idea is to do
%D that loading in vertical mode. Adding \type {\pushendofline} and \type
%D {\popendofline} is an option but not watertight as it can still interfere, for
%D instance work comments and leading spaces. Also, in horizontal mode it is likely
%D that one is also grouped and loading bodyfonts grouped is a real bad idea.
%D Ignoring all spaces is also not a solution. So, our verdict is: no catch.

\permanent\protected\def\starttypescriptcollection % redefined on the fly
  {\dosingleempty\font_typescripts_collection_start}

\def\font_typescripts_collection_start[#tag]%
  {}

\permanent\let\stoptypescriptcollection\relax

\permanent\protected\def\usetypescriptfile[#filename]%
  {\ifcstok{#filename}\v!reset
     \lettonothing\typescriptfiles
   \else
     \splitfilename{#filename}%
     \addtocommalist\splitoffbase\typescriptfiles
   \fi}

\installmacrostack\stoptypescript

% \permanent\protected\def\usetypescript     {\dotripleempty\font_typescripts_use_one}
% \permanent\protected\def\usetypescriptexact{\dotripleempty\font_typescripts_use_two}
%
% \def\font_typescripts_use_one{\let\typescriptmethod\plusone\font_typescripts_use}
% \def\font_typescripts_use_two{\let\typescriptmethod\plustwo\font_typescripts_use}
%
% \protected\def\font_typescripts_use[#one][#two][#three]%

% todo: just pass the method ... also further on then .. first test

\def\font_typescripts_use_one{\let\typescriptmethod\plusone\font_typescripts_use}
\def\font_typescripts_use_two{\let\typescriptmethod\plustwo\font_typescripts_use}

\permanent\protected\def\usetypescript     {\font_typescripts_use_one}
\permanent\protected\def\usetypescriptexact{\font_typescripts_use_two}

\tolerant\protected\def\font_typescripts_use[#one]#spacer[#two]#spacer[#three]%
  {\push_macro_m_font_typescripts_one
   \push_macro_m_font_typescripts_two
   \push_macro_m_font_typescripts_three
   \edef\m_font_typescripts_one  {\truetypescript{#one}}%
   \edef\m_font_typescripts_two  {\truetypescript{#two}}%
   \edef\m_font_typescripts_three{\truetypescript{#three}}%
   \push_macro_typescriptone
   \push_macro_typescripttwo
   \push_macro_typescriptthree
   \push_macro_typescriptmethod
   \push_macro_typescriptstate
   \push_macro_stoptypescript
   \typescriptfoundfalse
   \let\typescriptstate\plusone % why
   \iftracetypescripts
     \writestatus\m!fonts{request: [\m_font_typescripts_one] [\m_font_typescripts_two] [\m_font_typescripts_three]}%
   \fi
   \ifhmode
     \font_typescripts_use_inline
   \else
     \font_typescripts_use_display
   \fi
   \c_font_typescripts_first_pass\conditionalfalse
   \pop_macro_stoptypescript
   \pop_macro_typescriptstate
   \pop_macro_typescriptmethod
   \pop_macro_typescriptthree
   \pop_macro_typescripttwo
   \pop_macro_typescriptone
   \pop_macro_m_font_typescripts_three
   \pop_macro_m_font_typescripts_two
   \pop_macro_m_font_typescripts_one}

\def\font_typescripts_use_display
  {\processcommacommand[\typescriptfiles]\font_typescripts_load_file
   \expand\c_font_typescripts_document}

\let\font_typescripts_use_inline\font_typescripts_use_display

\permanent\protected\def\preloadtypescripts
  {\ifproductionrun\c_font_typescripts_preload\conditionaltrue\fi}

\prependtoks
    \preloadtypescripts
\to \everyjob

\permanent\protected\def\loadtypescriptfile[#1]%
  {\push_macro_typescriptstate
   \let\typescriptstate\plustwo % assumes 2 at the outer level
   \clf_loadtypescriptfile{#1}%
   \pop_macro_typescriptstate}

\permanent\protected\def\loadfoundtypescriptfile#1#2% name foundname / not a user command
  {\startreadingfile
   \unprotect
   \pushendofline
   \input{#2}%
   \popendofline
   \protect
   \stopreadingfile}

\permanent\protected\def\quittypescriptscanning
  {\c_font_typescripts_quit\conditionaltrue} % public

\permanent\protected\def\font_typescripts_start_store#definitions\stoptypescript
  {\global\advanceby\c_font_typescripts_n_of_preloaded\plusone
   \gdefcsname\??typescriptcache\the\c_font_typescripts_n_of_preloaded\endcsname
     {\starttypescript#definitions\stoptypescript}%
   \gtoksapp\t_font_typescripts\expandafter
     {\csname\??typescriptcache\the\c_font_typescripts_n_of_preloaded\endcsname}}

\permanent\protected\def\font_typescripts_collection_start_store#definitions\stoptypescriptcollection
  {\global\advanceby\c_font_typescripts_n_of_preloaded\plusone
   \gdefcsname\??typescriptcache\the\c_font_typescripts_n_of_preloaded\endcsname
     {\starttypescriptcollection#definitions\stoptypescriptcollection}%
   \gtoksapp\t_font_typescripts\expandafter
     {\csname\??typescriptcache\the\c_font_typescripts_n_of_preloaded\endcsname}}

\def\font_typescripts_load_file#filename%
  {\c_font_typescripts_quit\conditionalfalse
   \push_macro_currenttypefile
   \def\currenttypefile{#filename}%
   \ifconditional\c_font_typescripts_preload
     \font_typescript_process_typescript_file_and_store
   \else
     \font_typescript_process_typescript_file
   \fi
   \pop_macro_currenttypefile
   \ifconditional\c_font_typescripts_quit
     \quitcommalist
     \c_font_typescripts_quit\conditionalfalse
   \fi}

\def\font_typescript_process_typescript_file_and_store
  {\expandafter\let\expandafter\t_font_typescripts\csname\??typescriptfiles\currenttypefile\endcsname
   \ifrelax\t_font_typescripts
     \font_typescript_process_typescript_store_indeed
   \fi
   \expand\t_font_typescripts}

\def\font_typescript_process_typescript_store_indeed
  {\newtoks\t_font_typescripts % is \relaxed elsewhere
   \begingroup
     \enforced\let\starttypescript          \font_typescripts_start_store
     \enforced\let\starttypescriptcollection\font_typescripts_collection_start_store
     \font_typescript_process_typescript_file
   \endgroup
   \letcsname\??typescriptfiles\currenttypefile\endcsname\t_font_typescripts}

\def\font_typescript_process_typescript_file
  {\clf_loadtypescriptfile{\currenttypefile}}

\permanent\tolerant\protected\def\usetypescriptonce[#one]#spacer[#two]#spacer[#three]%
  {\ifcsname\??typescriptonce#one:#two:#three\endcsname
     \writestatus\m!fonts{once (#one) (#two) (#three)}%
   \else
     \letcsname\??typescriptonce#one:#two:#three\endcsname\relax
     \font_typescripts_use[#one][#two][#three]%
   \fi}

% \definetypescriptsynonym[lbr][cmr]

\permanent\tolerant\protected\def\definetypescriptsynonym[#name]#spacer[#synonym]%
  {\ifarguments\or\or\edefcsname\??typescriptsynonyms#name\endcsname{#synonym}\fi}

\permanent\def\truetypescript#name% recursive so no \lastnamedcs
  {\ifcsname\??typescriptsynonyms#name\endcsname
     \expandafter\truetypescript\lastnamedcs
   \else
     #name%
   \fi}

% script [serif] [default]         [size]
% script [serif] [computer-modern] [size]
% script [serif] [computer-modern] [ec]
% script [serif] [computer-modern] [name]
% script [serif] [computer-modern] [special]

\prependtoks
    \c_font_typescripts_first_pass\conditionaltrue
\to \everyjob

\permanent\protected\def\starttypescript
  {\ifcase\typescriptstate
     % 0 = skip
     \expandafter\font_typescripts_start_gobble
   \or
     % 1 = process
     \expandafter\font_typescripts_start_process
   \or
     % 2 = store
     \expandafter\font_typescripts_start_document
   \else
     % ? = skip
     \expandafter\font_typescripts_start_gobble
   \fi}

\def\font_typescripts_start_gobble#ignore\stoptypescript{}

\def\font_typescripts_start_document#definitions\stoptypescript
  {\toksapp\c_font_typescripts_document{\starttypescript#definitions\stoptypescript}}

\def\font_typescripts_start_process % could be a faster \doifelsenextoptionalif needed
  {\let\typescriptone  \m_font_typescripts_one
   \let\typescripttwo  \m_font_typescripts_two
   \let\typescriptthree\m_font_typescripts_three
   \lettonothing\m_font_typescripts_match
   \doifelsenextoptionalcs\font_typescripts_start_process_one\font_typescripts_start_process_all}

\def\font_typescripts_start_process_all % could be a \let
  {\ifconditional\c_font_typescripts_first_pass
     \expandafter\font_typescripts_start_process_indeed
   \else
     % skip this since it may do unwanted resets, like
     % setting symbolic font names to unknown, especially
     % in run time user type scripts
     \expandafter\font_typescripts_start_gobble
   \fi}

\def\font_typescripts_show_match
  {\writestatus\m!fonts{match:\ifrelax\currenttypefile\space *\fi \m_font_typescripts_match}}

\def\font_typescripts_start_process_yes
  {\ifdone
     \typescriptfoundtrue
     \iftracetypescripts\font_typescripts_show_match\fi
     \expandafter\font_typescripts_start_process_indeed
   \else
     \expandafter\font_typescripts_start_gobble
   \fi}

\def\font_typescripts_start_process_one
  {\font_typescripts_check\m_font_typescripts_one\typescriptone\font_typescripts_start_process_again_one}

\def\font_typescripts_start_process_two
  {\font_typescripts_check\m_font_typescripts_two\typescripttwo\font_typescripts_start_process_again_two}

\def\font_typescripts_start_process_three
  {\font_typescripts_check\m_font_typescripts_three\typescriptthree\font_typescripts_start_process_again_three}

\def\font_typescripts_start_process_again_one
  {\doifelsenextoptionalcs\font_typescripts_start_process_two\font_typescripts_start_process_yes}

\def\font_typescripts_start_process_again_two
  {\doifelsenextoptionalcs\font_typescripts_start_process_three\font_typescripts_start_process_yes}

\let\font_typescripts_start_process_again_three\font_typescripts_start_process_yes

\def\font_typescripts_start_process_indeed
  {\push_macro_fontclass}

\permanent\protected\def\stoptypescript
  {\pop_macro_fontclass}

\def\font_typescripts_check#asked#target#followup[#value]% script use value next
  {\donefalse
   \edef\m_font_typescripts_check{#value}%
   \ifempty\m_font_typescripts_check % no longer needed / met
     \ifcase\typescriptmethod\or\donetrue\fi
   \orelse\ifx#asked\s!all
     \donetrue
   \orelse\ifx\m_font_typescripts_check\s!all
     \donetrue
   \orelse\ifx#asked\m_font_typescripts_check % saves 10% trace so probably faster too
     \donetrue
     \let#target\m_font_typescripts_check
   \else
     \doifelsecommon\m_font_typescripts_check#asked\donetrue\donefalse
     \ifdone
       \let#target\commalistelement
     \fi
   \fi
   \ifdone
     \iftracetypescripts\extendtypescriptmatch\fi
     \expandafter#followup%
   \else
     \expandafter\font_typescripts_start_gobble
   \fi}

\permanent\protected\def\extendtypescriptmatch
  {\edef\m_font_typescripts_match{\m_font_typescripts_match\space[\m_font_typescripts_check]}}

%D Map files will go away in \LUATEX, but till that happens we use stripped down
%D support for loading them.

\permanent\tolerant\protected\def\loadmapfile             [#filename]{\clf_loadmapfile{#filename}}
\permanent\tolerant\protected\def\loadmapline   [#kind]#spacer[#data]{\clf_loadmapline{#kind}{#data}}
\permanent         \protected\def\forgetmapfiles                     {\clf_resetmapfiles}

% \prependtoks
%     \loadmapfile[mkiv-base.map]% can't we preload this one?
% \to \everystarttext

%D A handy shortcut:

% \definetypescriptprefix[serif][Serif]
% \definetypescriptprefix[sans] [Sans]
% \definetypescriptprefix[mono] [Mono]
%
% \starttypescript [serif,sans,mono] [handling,hanging,hz] [pure,normal,hz,quality]
%    \setupfontsynonym [\typescriptprefix\typescriptone] [handling=\typescriptthree]
% \stoptypescript

\permanent\tolerant\protected\def\definetypescriptprefix[#name]#spacer[#prefix]%
  {\gdefcsname\??typescriptprefix#name\endcsname{#prefix}} % made global

\permanent\def\typescriptprefix#name%
  {\ifcsname\??typescriptprefix#name\endcsname\lastnamedcs\else#name\fi}

% defining typefaces:
%
% \definetypeface [joke] [rm]
% \definetypeface [joke] [rm] [settings]
% \definetypeface [joke] [rm] [serif] [lucida]
% \definetypeface [joke] [rm] [serif] [lucida] [size]
% \definetypeface [joke] [rm] [serif] [lucida] [size] [settings]
% \definetypeface [joke] [specification]

\appendtoks
    \font_helpers_reset_fontclass_math_families\fontclass
\to \everybeforedefinetypeface

%D This hooks into the font switcher:

\newconditional\autotypescripts  \autotypescripts\conditionaltrue

\protected\def\fonts_helpers_try_currentfontclass#typeface%
  {\ifconditional\autotypescripts
     \usetypescript[#typeface]%
     \ifcsname\??fontclassyes#typeface\endcsname
       \cdef\fontclass{#typeface}%
     \else
       \iftracetypescripts\writestatus\m!fonts{auto load typescript file 1: [#typeface]}\fi
       \usetypescriptfile[#typeface]%
       \usetypescript[#typeface]%
       \ifcsname\??fontclassyes#typeface\endcsname
         \cdef\fontclass{#typeface}%
       \else
         % todo: message
% \gletcsname
         \letcsname\??fontclassnop#typeface\endcsname\empty
       \fi
     \fi
   \else
     % todo: message
% \gletcsname
     \letcsname\??fontclassnop#typeface\endcsname\empty
   \fi}

%D Now we define:

\permanent\tolerant\protected\def\definetypeface[#name]#spacer[#style]#spacer[#fontshape]#spacer[#fontname]#spacer[#fontsize]#spacer[#settings]%
  {\ifarguments
     \expandafter\font_typefaces_define_e
   \or
     \expandafter\font_typefaces_define_d
   \or
     \expandafter\font_typefaces_define_d
   \or
     \expandafter\font_typefaces_define_c
   \or
     \expandafter\font_typefaces_define_b
   \or
     \expandafter\font_typefaces_define_a
   \or
     \expandafter\font_typefaces_define_a
   \fi[#name][#style][#fontshape][#fontname][#fontsize][#settings]}

\def\font_typefaces_define_e[#name][#style][#fontshape][#fontname][#fontsize][#settings]%
  {}

\def\font_typefaces_define_a[#name][#style][#fontshape][#fontname][#fontsize][#settings]%
  {\iftracetypescripts\writestatus\m!fonts{define: [#name] [#style] [#fontshape] [#fontname]}\fi
   \font_typefaces_define_indeed[#name][#style]%
   \font_typefaces_defining_start{#name}{#style}{#settings}%
     \font_typescripts_use_one[#fontshape][#fontname][\s!name]% [\s!name,\s!default]%
     \iftypescriptfound
       % we're okay
     \orelse\ifconditional\autotypescripts
       \iftracetypescripts\writestatus\m!fonts{auto load typescript file 2: [#fontname]}\fi
       \usetypescriptfile[#fontname]%
       \font_typescripts_use_one[#fontshape][#fontname][\s!name]% [\s!name,\s!default]%
     \fi
     \font_typescripts_use_one[#fontshape][#fontsize][\s!size]%
   \font_typefaces_defining_stop}

\def\font_typefaces_define_b[#name][#style][#fontshape][#fontname][#discard][#discard]%
  {\font_typefaces_define_a[#name][#style][#fontshape][#fontname][\s!default][#discard]}

\def\font_typefaces_define_c[#name][#style][#discard][#discard][#discard][#discard]%
  {\font_typefaces_define_indeed[#name][#style]}

\def\font_typefaces_define_d[#name][#specification][#discard][#discard][#discard][#discard]% use definitions in lfg file
  {\clf_definetypeface{#name}{#specification}}

\def\font_typefaces_define_indeed[#name][#style]% saveguard against redefinition
  {\ifempty{#name}\else
     \ifcsname\??typescriptdefaultstyles#name\endcsname \else
       \registerfontclass{#name}%
       \gdefcsname\??typescriptdefaultstyles#name\endcsname{#style}%
     \fi
     \ifcsname#name\endcsname \else
       \protected\frozen\instance\gdefcsname#name\endcsname{\switchtotypeface[#name][#style]}%
     \fi
   \fi}

\lettonothing\m_ts_features
\lettonothing\m_ts_fallbacks
\lettonothing\m_ts_goodies
\lettonothing\m_ts_designsize

\def\font_typefaces_defining_start#name#style#settings%
  {\let\m_ts_rscale\!!plusone % as we push/pop
   \lettonothing\m_ts_features
   \lettonothing\m_ts_fallbacks
   \lettonothing\m_ts_goodies
   \lettonothing\m_ts_designsize
   \geteparameters[m_ts_][#settings]% todo raw ... no need for key interpretation
   \push_macro_fontclass
   \push_macro_fontclassstyle
   \setcurrentfontclass{#name}%
   \savefontclassparameters{#style}\m_ts_rscale\m_ts_features\m_ts_fallbacks\m_ts_goodies\m_ts_designsize
   \expand\everybeforedefinetypeface}

\permanent\def\tsvar#key#default% undocumented and unofficial
  {\expandafter\ifempty\csname\??ts#key\endcsname
     #default%
   \else
     \csname\??ts#key\endcsname
   \fi}

\def\font_typefaces_defining_stop
  {\expand\everyafterdefinetypeface
   \pop_macro_fontclassstyle
   \pop_macro_fontclass}

\permanent\protected\def\dofastdefinetypeface#name#style#fontshape#fontsize#settings% called from the lua end (via case d)
  {\font_typefaces_define_indeed[#name][#style]%
   \font_typefaces_defining_start{#name}{#style}{#settings}%
   \font_typescripts_use_one[#fontshape][#fontsize][\s!size]%
   \font_typefaces_defining_stop}

\permanent\tolerant\protected\def\setuptypeface[#class]#spacer[#settings]%
  {\ifarguments
   \or
     \setcurrentfontclass{#class}%
     \let\globalfontclass\fontclass
     \ifempty\fontclass
       \setupbodyfont[\s!rm]%
     \orelse\ifcsname\??typescriptdefaultstyles\fontclass\endcsname
       \expandafter\setupbodyfont\expandafter[\lastnamedcs]%
     \else
       \setupbodyfont[\s!rm]%
     \fi
   \or
     \setcurrentfontclass{#class}%
     \let\globalfontclass\fontclass
     \setupbodyfont[#settings]%
   \fi
   \ifmmode\mr\else\tf\fi} % needed ?

\permanent\tolerant\protected\def\switchtotypeface[#class]#spacer[#settings]%
  {\ifarguments
   \or
     \setcurrentfontclass{#class}%
     \let\globalfontclass\globalfontclass
     \ifempty\fontclass
       \switchtobodyfont[\s!rm]%
     \orelse\ifcsname\??typescriptdefaultstyles\fontclass\endcsname
       \expandafter\switchtobodyfont\expandafter[\lastnamedcs]%
     \else
       \switchtobodyfont[\s!rm]%
     \fi
   \or
     \setcurrentfontclass{#class}%
     \let\globalfontclass\globalfontclass
       \switchtobodyfont[#settings]%
   \fi
   \ifmmode\mr\else\tf\fi} % needed ?

%D For Taco:
%D
%D \starttyping
%D \inherittypeface[palatino][rm][postscript]
%D \inherittypeface[palatino][rm][\fontclass]
%D \inherittypeface[palatino][rm] % == \fontclass
%D \inherittypeface[palatino] % == [rm,ss,tt,mm]
%D \stoptyping

\permanent\tolerant\protected\def\inherittypeface[#name]#spacer[#styles]#spacer[#parentclass]%
  {\ifempty{#styles}%
     \inherittypeface[#name][\s!rm,\s!ss,\s!tt,\s!mm][\fontclass]%
   \orelse\iftok{#name}{#parentclass}\else
     \glet\font_typescripts_inherit_check\font_typescripts_inherit_check_indeed
     \def\font_typescripts_inherit_check_step#style{\edefcsname\??typescriptinheritances#name:#style\endcsname{#parentclass}}%
     \processcommalist[#styles]\font_typescripts_inherit_check_step
   \fi}

\let\font_typescripts_inherit_check_step\relax

%D This hooks into the font mechanism with:

\def\font_typescripts_inherit_check_indeed#name% called often
  {\ifcsname\??typescriptinheritances\fontclass:#name\endcsname
    %\expandafter\let\expandafter\fontclass\csname\??typescriptinheritances\fontclass:#name\endcsname
     \expandafter\let\expandafter\fontclass\lastnamedcs
   \fi}

\let\font_typescripts_inherit_check\gobbleoneargument

\def\v_font_string_d % default fontstyle (expands to \s!Serif in font-ini)
  {\expandafter\ifx\csname\??typescriptdefaultstyles\fontclass\endcsname\s!rm \s!Serif \else % no \orelse !
   \expandafter\ifx\csname\??typescriptdefaultstyles\fontclass\endcsname\s!ss \s!Sans  \else % no \orelse !
   \expandafter\ifx\csname\??typescriptdefaultstyles\fontclass\endcsname\s!tt \s!Mono  \else % no \orelse !
                                                                              \s!Serif \fi\fi\fi}

\protected\def\font_helpers_set_fontstyle_of_fontclass
  {\ifempty\fontclass
     \let\fontstyle\s!rm
   \orelse\ifcsname\??typescriptdefaultstyles\fontclass\endcsname
    %\edef\fontstyle{\csname\??typescriptdefaultstyles\fontclass\endcsname}%
     \edef\fontstyle{\lastnamedcs}%
   \else
     \let\fontstyle\s!rm
   \fi}

\protect \endinput
