%% The LaTeX package tcolorbox - version 4.14 (2018/07/26)
%% tcbvignette.code.tex: Code for ornamental frames
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2006-2018 by Prof. Dr. Dr. Thomas F. Sturm <thomas dot sturm at unibw dot de>
%% -------------------------------------------------------------------------------------------
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `author-maintained'.
%%
%% This work consists of all files listed in README
%%
\tcb@set@library@version{4.14}

\tcbuselibrary{skins}

\usetikzlibrary{fadings}

\pgfdeclarehorizontalshading{tcb@fade@east}{100bp}
{color(0bp)=(pgftransparent!50); color(25bp)=(pgftransparent!50);
 color(75bp)=(pgftransparent!100); color(100bp)=(pgftransparent!100)}

\pgfdeclarehorizontalshading{tcb@fade@west}{100bp}
{color(0bp)=(pgftransparent!100); color(25bp)=(pgftransparent!100);
 color(75bp)=(pgftransparent!50); color(100bp)=(pgftransparent!50)}

\pgfdeclareverticalshading{tcb@fade@north}{100bp}
{color(0bp)=(pgftransparent!50); color(25bp)=(pgftransparent!50);
 color(75bp)=(pgftransparent!100); color(100bp)=(pgftransparent!100)}

\pgfdeclareverticalshading{tcb@fade@south}{100bp}
{color(0bp)=(pgftransparent!100); color(25bp)=(pgftransparent!100);
 color(75bp)=(pgftransparent!50); color(100bp)=(pgftransparent!50)}

\pgfdeclarefading{semi east}{\pgfuseshading{tcb@fade@east}}
\pgfdeclarefading{semi west}{\pgfuseshading{tcb@fade@west}}
\pgfdeclarefading{semi north}{\pgfuseshading{tcb@fade@north}}
\pgfdeclarefading{semi south}{\pgfuseshading{tcb@fade@south}}

\def\tcb@vig@draw@north#1{\path[#1]\pgfextra{%
  \pgfpathmoveto{\pgfqpoint{\tcb@vig@xA}{\tcb@vig@yB}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xB}{\tcb@vig@yB}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xb}{\tcb@vig@yb}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xa}{\tcb@vig@yb}}%
  \pgfpathclose};}

\def\tcb@vig@draw@east#1{\path[#1]\pgfextra{%
  \pgfpathmoveto{\pgfqpoint{\tcb@vig@xB}{\tcb@vig@yB}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xB}{\tcb@vig@yA}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xb}{\tcb@vig@ya}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xb}{\tcb@vig@yb}}%
  \pgfpathclose};}

\def\tcb@vig@draw@south#1{\path[#1]\pgfextra{%
  \pgfpathmoveto{\pgfqpoint{\tcb@vig@xB}{\tcb@vig@yA}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xA}{\tcb@vig@yA}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xa}{\tcb@vig@ya}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xb}{\tcb@vig@ya}}%
  \pgfpathclose};}

\def\tcb@vig@draw@west#1{\path[#1]\pgfextra{%
  \pgfpathmoveto{\pgfqpoint{\tcb@vig@xA}{\tcb@vig@yA}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xA}{\tcb@vig@yB}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xa}{\tcb@vig@yb}}%
  \pgfpathlineto{\pgfqpoint{\tcb@vig@xa}{\tcb@vig@ya}}%
  \pgfpathclose};}

\def\tcb@vig@draw@direct{%
  \ifdim\tcb@vig@yB>\tcb@vig@yb\relax%
    \begingroup\edef\x{\endgroup\noexpand\tcb@vig@draw@north{fill,draw=none,\expandonce\tcb@vig@style@north}}\x%
  \fi%
  \ifdim\tcb@vig@xB>\tcb@vig@xb\relax%
    \begingroup\edef\x{\endgroup\noexpand\tcb@vig@draw@east{fill,draw=none,\expandonce\tcb@vig@style@east}}\x%
  \fi%
  \ifdim\tcb@vig@yA<\tcb@vig@ya\relax%
    \begingroup\edef\x{\endgroup\noexpand\tcb@vig@draw@south{fill,draw=none,\expandonce\tcb@vig@style@south}}\x%
  \fi%
  \ifdim\tcb@vig@xA<\tcb@vig@xa\relax%
    \begingroup\edef\x{\endgroup\noexpand\tcb@vig@draw@west{fill,draw=none,\expandonce\tcb@vig@style@west}}\x%
  \fi%
}

\def\tcb@vig@draw@clipped{%
  \ifdim\tcb@vig@yB>\tcb@vig@yb\relax%
    \begin{scope}
    \tcb@vig@draw@north{clip}%
    \begingroup\edef\x{\endgroup\noexpand\path[fill,\expandonce\tcb@vig@style@north]}%
    \x\pgfextra{\pgfpathrectanglecorners{\pgfpoint{\tcb@vig@xA-1mm}{\tcb@vig@yb}}%
        {\pgfpoint{\tcb@vig@xB+1mm}{\tcb@vig@yB}}};
    \end{scope}
  \fi%
  \ifdim\tcb@vig@xB>\tcb@vig@xb\relax%
    \begin{scope}
    \tcb@vig@draw@east{clip}%
    \begingroup\edef\x{\endgroup\noexpand\path[fill,\expandonce\tcb@vig@style@east]}%
    \x\pgfextra{\pgfpathrectanglecorners{\pgfpoint{\tcb@vig@xb}{\tcb@vig@yA-1mm}}%
          {\pgfpoint{\tcb@vig@xB}{\tcb@vig@yB+1mm}}};
    \end{scope}
  \fi%
  \ifdim\tcb@vig@yA<\tcb@vig@ya\relax%
    \begin{scope}
    \tcb@vig@draw@south{clip}%
    \begingroup\edef\x{\endgroup\noexpand\path[fill,\expandonce\tcb@vig@style@south]}%
    \x\pgfextra{\pgfpathrectanglecorners{\pgfpoint{\tcb@vig@xA-1mm}{\tcb@vig@yA}}%
        {\pgfpoint{\tcb@vig@xB+1mm}{\tcb@vig@ya}}};
    \end{scope}
  \fi%
  \ifdim\tcb@vig@xA<\tcb@vig@xa\relax%
    \begin{scope}
    \tcb@vig@draw@west{clip}%
    \begingroup\edef\x{\endgroup\noexpand\path[fill,\expandonce\tcb@vig@style@west]}%
    \x\pgfextra{%
      \pgfpathrectanglecorners{\pgfpoint{\tcb@vig@xA}{\tcb@vig@yA-1mm}}%
        {\pgfpoint{\tcb@vig@xa}{\tcb@vig@yB+1mm}}};
    \end{scope}
  \fi%
}

\newcommand{\tcbvignette}[1]{%
  \ifdefined\pgfpictureid%
    \begingroup%
    \tcbset{vig/.cd,#1}%
    \tcbdimto\tcb@vig@xA{\tcb@vig@xmin}%
    \tcbdimto\tcb@vig@xB{\tcb@vig@xmax}%
    \tcbdimto\tcb@vig@yA{\tcb@vig@ymin}%
    \tcbdimto\tcb@vig@yB{\tcb@vig@ymax}%
    \tcbdimto\tcb@vig@xa{\tcb@vig@xA+\tcb@vig@size@west}%
    \tcbdimto\tcb@vig@xb{\tcb@vig@xB-(\tcb@vig@size@east)}%
    \tcbdimto\tcb@vig@ya{\tcb@vig@yA+\tcb@vig@size@south}%
    \tcbdimto\tcb@vig@yb{\tcb@vig@yB-(\tcb@vig@size@north)}%
    \begin{scope}[tcb@vig@scope]%
    \tcb@vig@draw%
    \end{scope}
    \endgroup%
  \else%
    \tcb@warning{'tcbvignette' was found outside a 'tikzpicture' environment and is ignored}%
  \fi%
}

\tcbset{%
  vig/.cd,
  xmin/.store in=\tcb@vig@xmin,
  xmax/.store in=\tcb@vig@xmax,
  ymin/.store in=\tcb@vig@ymin,
  ymax/.store in=\tcb@vig@ymax,
  lower left corner/.code={\tcb@gettikzxy{(#1)}{\tcb@vig@xmin}{\tcb@vig@ymin}},
  upper right corner/.code={\tcb@gettikzxy{(#1)}{\tcb@vig@xmax}{\tcb@vig@ymax}},
  %
  inside node/.style={lower left corner={#1.south west},upper right corner={#1.north east}},
  outside node/.style={lower left corner={[xshift=-\tcb@vig@size@west,yshift=-\tcb@vig@size@south]#1.south west},
    upper right corner={[xshift=\tcb@vig@size@east,yshift=\tcb@vig@size@north]#1.north east}},
  %
  on node/.style={lower left corner={#1.south west},upper right corner={#1.north east}},
  over node offset/.store in=\tcb@vig@onoffset,%
  over node/.style={lower left corner={[xshift=-\tcb@vig@onoffset,yshift=-\tcb@vig@onoffset]#1.south west},
    upper right corner={[xshift=\tcb@vig@onoffset,yshift=\tcb@vig@onoffset]#1.north east}},
  north size/.store in=\tcb@vig@size@north,
  south size/.store in=\tcb@vig@size@south,
  east size/.store in=\tcb@vig@size@east,
  west size/.store in=\tcb@vig@size@west,
  vertical size/.style={north size=#1,south size=#1},
  horizontal size/.style={east size=#1,west size=#1},
  size/.style={north size=#1,south size=#1,east size=#1,west size=#1},
  north style/.store in=\tcb@vig@style@north,
  south style/.store in=\tcb@vig@style@south,
  east style/.store in=\tcb@vig@style@east,
  west style/.store in=\tcb@vig@style@west,
  scope/.code={\tikzset{tcb@vig@scope/.style={#1}}},
  draw method/.is choice,
  draw method/direct/.code={\let\tcb@vig@draw\tcb@vig@draw@direct},%
  draw method/clipped/.code={\let\tcb@vig@draw\tcb@vig@draw@clipped},%
  base color/.colorlet=tcbcol@vig@base,
  raised color/.style={%
    base color=#1,
    north style={tcbcol@vig@base!50!white},
    east style={tcbcol@vig@base!75!black},
    south style={tcbcol@vig@base!50!black},
    west style={tcbcol@vig@base!75!white},
  },
  lowered color/.style={%
    base color=#1,
    north style={tcbcol@vig@base!50!black},
    east style={tcbcol@vig@base!75!white},
    south style={tcbcol@vig@base!50!white},
    west style={tcbcol@vig@base!75!black},
  },
  color from/.style args={#1 to #2}{%
    north style={bottom color=#1,top color=#2},
    east style={left color=#1,right color=#2},
    south style={top color=#1,bottom color=#2},
    west style={right color=#1,left color=#2},
  },
  fade in/.style={%
    north style={#1,path fading=south},
    east style={#1,path fading=west},
    south style={#1,path fading=north},
    west style={#1,path fading=east},
  },
  fade in/.default=white,
  fade out/.style={%
    north style={#1,path fading=north},
    east style={#1,path fading=east},
    south style={#1,path fading=south},
    west style={#1,path fading=west},
  },
  fade out/.default=white,
  semi fade in/.style={%
    north style={#1,path fading=semi south},
    east style={#1,path fading=semi west},
    south style={#1,path fading=semi north},
    west style={#1,path fading=semi east},
  },
  semi fade in/.default=white,
  semi fade out/.style={%
    north style={#1,path fading=semi north},
    east style={#1,path fading=semi east},
    south style={#1,path fading=semi south},
    west style={#1,path fading=semi west},
  },
  semi fade out/.default=white,
  %
  scope=,
  draw method=direct,
  xmin=0pt,
  xmax=1cm,
  ymin=0pt,
  ymax=1cm,
  size=2mm,
  over node offset=0.1mm,
  raised color=red,
}

\tcbset{%
  finish@vignette/.style 2 args={finish #1={%
    \begin{tcbclipframe}\tcbvignette{%
      scope={transparency group,opacity=0.25},
      north style=white,
      east style=black!75,
      south style=black,
      west style=black!25,#2,inside node=frame
      }\end{tcbclipframe}}},
  finish vignette/.style={%
    finish@vignette={unbroken}{#1},%
    finish@vignette={first}{#1,south size=0pt},%
    finish@vignette={middle}{#1,north size=0pt,south size=0pt},%
    finish@vignette={last}{#1,north size=0pt}%
  },
%
  finish@raised@vignette/.style 2 args={finish #1={%
    \begin{tcbclipframe}\tcbvignette{%
      draw method=clipped,
      north style={white,path fading=semi south},
      east style={black!75,path fading=semi west},
      south style={black,path fading=semi north},
      west style={black!25,path fading=semi east},#2,inside node=frame
      }\end{tcbclipframe}}},
  finish raised fading vignette/.style={%
    finish@raised@vignette={unbroken}{#1},%
    finish@raised@vignette={first}{#1,south size=0pt},%
    finish@raised@vignette={middle}{#1,north size=0pt,south size=0pt},%
    finish@raised@vignette={last}{#1,north size=0pt}%
  },
%
  finish@fading@vignette/.style 2 args={finish #1={%
    \tcbvignette{%
      draw method=clipped,fade in=tcbcol@vig@base,#2,over node=frame}}},
  finish fading vignette/.style={%
    finish@fading@vignette={unbroken}{base color=white,#1},%
    finish@fading@vignette={first}{base color=white,#1,south size=0pt},%
    finish@fading@vignette={middle}{base color=white,#1,north size=0pt,south size=0pt},%
    finish@fading@vignette={last}{base color=white,#1,north size=0pt}%
  },
%
  underlay@vignette/.style 2 args={underlay #1={%
    \begin{tcbclipframe}\tcbvignette{%
      raised color=tcbcol@frame,
      north size=\kvtcb@top@rule@stand,
      south size=\kvtcb@bottom@rule@stand,
      west size=\kvtcb@left@rule,
      east size=\kvtcb@right@rule,#2,inside node=frame
      }\end{tcbclipframe}}},
  underlay vignette/.style={%
    underlay@vignette={unbroken}{#1},%
    underlay@vignette={first}{#1,south size=0pt},%
    underlay@vignette={middle}{#1,north size=0pt,south size=0pt},%
    underlay@vignette={last}{#1,north size=0pt}%
  },
%
  underlay@fading@vignette/.style 2 args={underlay #1={%
    \begin{tcbclipframe}\tcbvignette{%
      draw method=clipped,
      north style={white,path fading=semi south},
      east style={black!75,path fading=semi west},
      south style={black,path fading=semi north},
      west style={black!25,path fading=semi east},#2,inside node=frame,
      }\end{tcbclipframe}}},
  underlay raised fading vignette/.style={%
    underlay@fading@vignette={unbroken}{#1},%
    underlay@fading@vignette={first}{#1,south size=0pt},%
    underlay@fading@vignette={middle}{#1,north size=0pt,south size=0pt},%
    underlay@fading@vignette={last}{#1,north size=0pt}%
  },
  %
  underlay raised shading vignette/.style={%
    underlay vignette={draw method=clipped,
      north style={bottom color=tcbcol@frame,top color=tcbcol@frame!33!white},
      east style={left color=tcbcol@frame,right color=tcbcol@frame!66!black},
      south style={top color=tcbcol@frame,bottom color=tcbcol@frame!33!black},
      west style={right color=tcbcol@frame,left color=tcbcol@frame!66!white},#1}},
  %
  underlay shade in vignette/.style={%
    underlay vignette={draw method=clipped,color from=tcbcol@back to tcbcol@frame,#1}},
}
