%% This is file `colorspace-patches-tmp-ltx.sty"
% Copyright (C) 2019-2022 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 "pdfmanagement bundle" (The Work in LPPL)
% and all files in that bundle must be distributed together.
%
% -----------------------------------------------------------------------
%
% The development version of the bundle can be found at
%
%    https://github.com/latex3/pdfresources
%
% for those people who are interested.
\NeedsTeXFormat{LaTeX2e}[2020/10/01]
\ProvidesExplPackage{colorspace-patches-tmp-ltx}{2026-01-23}{0.96y}
  {temporary patches for the colorspace package to test pdfresource management ... UF}


% colorspace can define more models, that l3color can't yet handle.
\cs_set_protected:Npn \expl@color@set@@nnn #1#2#3
 {
   \cs_if_exist:cT { __color_parse_model_ #2 :w }
    { \color_set:nnn{#1}{#2}{#3} }
 }


\hook_gput_code:nnn {begindocument} {pdf}
  {
    \tl_if_exist:NT \spc@op
      {
        \def\spc@Pageresources#1{}
      }
  }

\hook_gput_code:nnn {begindocument/end} {pdf}
  {
    \tl_if_exist:NT \spc@op
      {
        \pdf_object_new:n  {__spc_extgstate_op_false}
        \pdf_object_write:nnn
          {__spc_extgstate_op_false}{dict}
          {/Type /ExtGState~/op~false~/OP~false}
        \pdfmanagement_add:nnn
          {Page/Resources/ExtGState}
          {SPCko}
          {\pdf_object_ref:n {__spc_extgstate_op_false}}
        \pdf_object_new:n  {__spc_extgstate_op_true0}
        \pdf_object_write:nnn
          {__spc_extgstate_op_true0}{dict}
          {/Type /ExtGState~/op~true~/OP~true~/OPM~0}%
        \pdfmanagement_add:nnn
          {Page/Resources/ExtGState}
          {SPCmz}
          {\pdf_object_ref:n {__spc_extgstate_op_true0}}
        \pdf_object_new:n  {__spc_extgstate_op_true1}
        \pdf_object_write:nnn
          {__spc_extgstate_op_true1}{dict}
          {/Type /ExtGState~/op~true~/OP~true~/OPM~1}%
         \pdfmanagement_add:nnn
          {Page/Resources/ExtGState}
          {SPCop}
          {\pdf_object_ref:n {__spc_extgstate_op_true1}}
      }
  }

\RemoveFromHook{begindocument}[colorspace]

\hook_gput_code:nnn {begindocument/end} {pdf}
 {
  \def\spc@elt#1#2
   {
    \str_set_eq:Nc\l_tmpa_str {spc@ir@#2}
    \seq_set_split:NnV \l_tmpa_seq {~}\l_tmpa_str
    \seq_get_left:NN\l_tmpa_seq\l_tmpa_str
    %remove spaces
    \exp_args:NNe
    \str_replace_all:Nnn\l_tmpa_str {\c_hash_str20}{~}
    %remove slash
    \str_set:Ne\l_tmpa_str{\str_tail:N\l_tmpa_str}
    \pdfmanagement_add:nee
      {Page/Resources/ColorSpace}{\l_tmpa_str}{\seq_item:Nn\l_tmpa_seq{2}~0~R}
   }
   \spc@csall
 }

\endinput
