1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-03-01 09:20:02 +00:00
2025-02-04 16:10:38 +00:00

187 lines
8.2 KiB
Plaintext

title: $:/core/macros/CSS
tags: $:/tags/Macro
\procedure actions-compile-palette-filtered(tempPalette,outputTitle,scheme)
<!-- Note the join, needed to cope with palette entries containing spaces -->
\function colour(name) [<name>addsuffix[@]addsuffix<scheme>] :map[<tempPalette>getindex<currentTiddler>] +[!match[]] :else[<tempPalette>getindex<name>] :else[[$:/config/DefaultColourMappings/]addsuffix<name>addsuffix[@]addsuffix<scheme>get[text]] :else[[$:/config/DefaultColourMappings/]addsuffix<name>get[text]] :map[subfilter<currentTiddler>join[ ]]
\function color(name) [function[colour],<name>]
<!-- Make the colour function use the input palette -->
<$list filter="[<tempPalette>indexes[]sort[]]" variable="colour-name">
<$let filter-text={{{ [<colour-name>addsuffix[@]addsuffix<scheme>] :map[<tempPalette>getindex<currentTiddler>] +[!match[]] :else[<tempPalette>getindex<colour-name>] :else[[$:/config/DefaultColourMappings/]addsuffix<colour-name>addsuffix[@]addsuffix<scheme>get[text]] :else[[$:/config/DefaultColourMappings/]addsuffix<colour-name>get[text]] }}}>
<!-- Note the join, needed to cope with palette entries containing spaces -->
<$action-setfield $tiddler=<<outputTitle>> $index=<<colour-name>> $value={{{ [subfilter<filter-text>join[ ]] }}}/>
</$let>
</$list>
\end actions-compile-palette-filtered
\procedure actions-compile-palette-wikified(tempPalette,outputTitle,scheme)
<!-- Define our own deeply backwards compatible local versions of the colour macro -->
\define colour(name)
\whitespace trim
<$transclude tiddler=<<tempPalette>> index="$name$@$(scheme)$">
<$transclude tiddler=<<tempPalette>> index="$name$">
<$transclude tiddler="$:/config/DefaultColourMappings/$name$@$(scheme)$">
<$transclude tiddler="$:/config/DefaultColourMappings/$name$"/>
</$transclude>
</$transclude>
</$transclude>
\end colour
\define color(name) <<colour $name$>>
<$list filter="[<tempPalette>indexes[]sort[]]" variable="colour-name" $debug="yes">
<$let
palette-entry-text={{{ [<colour-name>addsuffix[@]addsuffix<scheme>] :map[<tempPalette>getindex<currentTiddler>] +[!match[]] :else[<tempPalette>getindex<colour-name>] :else[[$:/config/DefaultColourMappings/]addsuffix<colour-name>get[text]] }}}
>
<$wikify name="colour-value" text=<<palette-entry-text>> mode="inline">
<$action-setfield $tiddler=<<outputTitle>> $index=<<colour-name>> $value=<<colour-value>>/>
</$wikify>
</$let>
</$list>
\end actions-compile-palette-wikified
\procedure actions-compile-palette-import(inputTitle,outputTitle,exclusions:"",scheme)
<%if [enlist<exclusions>!match<inputTitle>count[]] :map[enlist<exclusions>count[]compare:number:eq<currentTiddler>] +[!match[]] %>
<$set name="exclusions" filter="[enlist<exclusions>] [<inputTitle>]">
<$let
prefixed-palette-import={{{ [[palette-import@]addsuffix<scheme>] }}}
inputTitle={{{ [<inputTitle>get<prefixed-palette-import>has[title]] :else[<inputTitle>get[palette-import]] }}}
>
<%if [<inputTitle>has[title]] %>
<$transclude $variable="actions-compile-palette-import" inputTitle=<<inputTitle>> outputTitle=<<outputTitle>> exclusions=<<exclusions>> scheme=<<scheme>>/>
<%endif%>
</$let>
<$action-setmultiplefields $tiddler=<<outputTitle>> $indexes="[<inputTitle>indexes[]sort[]]" $values="[<inputTitle>indexes[]sort[]] :map[<inputTitle>getindex<currentTiddler>]"/>
<$action-setmultiplefields $tiddler=<<outputTitle>> $fields="[<inputTitle>fields[]sort[]] -title -tags -text" $values="[<inputTitle>fields[]sort[]] -title -tags -text :map[<inputTitle>get<currentTiddler>]"/>
</$set>
<%endif%>
\end actions-compile-palette-import
\procedure actions-compile-palette(inputTitle,outputTitle,defaultImport="$:/palettes/Vanilla")
\procedure tv-action-refresh-policy() always
<$let
tempPalette="$:/temp/palette-consolidated"
>
<!-- Compute the current scheme -->
<$let
color-scheme-filter={{{ [<inputTitle>get[color-scheme]] :else[[light]] }}}
scheme={{{ [subfilter<color-scheme-filter>] }}}
>
<!-- Clear the temporary consolidated palette -->
<$action-deletetiddler $tiddler=<<tempPalette>>/>
<$action-setfield $tiddler=<<tempPalette>> type="application/x-tiddler-dictionary"/>
<$action-deletetiddler $tiddler=<<outputTitle>>/>
<$action-setfield $tiddler=<<outputTitle>> type="application/x-tiddler-dictionary"/>
<!-- Consolidate the chain of palettes -->
<$transclude $variable="actions-compile-palette-import" inputTitle=<<inputTitle>> outputTitle=<<tempPalette>> scheme=<<scheme>>/>
<!-- Clear the output palette and assign the scheme -->
<$action-setfield $tiddler=<<outputTitle>> $field="color-scheme" $value=<<scheme>>/>
<!-- Compile the temporary palette to the output palette -->
<%if [<inputTitle>get[palette-type]match[modern]] %>
<$transclude $variable="actions-compile-palette-filtered" tempPalette=<<tempPalette>> outputTitle=<<outputTitle>> scheme=<<scheme>>/>
<%else%>
<$transclude $variable="actions-compile-palette-wikified" tempPalette=<<tempPalette>> outputTitle=<<outputTitle>> scheme=<<scheme>>/>
<%endif%>
<!-- Remove the temporary consolidated palette -->
<!-- <$action-deletetiddler $tiddler=<<tempPalette>>/> -->
</$let>
</$let>
\end actions-compile-palette
\procedure actions-recompile-current-palette()
\procedure tv-action-refresh-policy() always
<$transclude $variable="actions-compile-palette" inputTitle={{$:/palette}} outputTitle="$:/temp/palette-colours"/>
\end actions-recompile-current-palette
\procedure actions-switch-colour-palette(paletteTitle)
\procedure tv-action-refresh-policy() always
<$action-deletetiddler $tiddler="$:/temp/palette-colours"/>
<<actions-recompile-current-palette>>
\end actions-switch-colour-palette
\procedure tv-palette-name() $:/temp/palette-colours
\function colour(name)
[<tv-palette-name>get[colour-scheme]addprefix[@]addprefix<name>] :map[<tv-palette-name>getindex<currentTiddler>] +[!match[]] :else[<tv-palette-name>getindex<name>] :else[[$:/config/DefaultColourMappings/]addsuffix<name>get[text]]
\end colour
\function color(name)
[function[colour],<name>]
\end color
\function tf.check-colour-contrast-subfunction()
[function[colour],<paletteEntryA>] [function[colour],<paletteEntryB>] +[colour-contrast:DeltaPhi[]fixed[3]]
\end tf.check-colour-contrast-subfunction
\function tf.check-colour-contrast(paletteEntryA,paletteEntryB,threshold)
[function[tf.check-colour-contrast-subfunction]compare:number:gt<threshold>then[ok]] :else[function[tf.check-colour-contrast-subfunction]addsuffix[: ]addsuffix<paletteEntryA>addsuffix[/]addsuffix<paletteEntryB>addsuffix[ contrast is too low]]
\end tf.check-colour-contrast
\function tf.interpolate-colours(paletteEntryA,paletteEntryB,weight)
[function[colour],<paletteEntryA>] [function[colour],<paletteEntryB>] +[colour-interpolate:oklch<weight>]
\end tf.interpolate-colours
\define box-shadow(shadow)
``
-webkit-box-shadow: $shadow$;
-moz-box-shadow: $shadow$;
box-shadow: $shadow$;
``
\end
\define filter(filter)
``
-webkit-filter: $filter$;
-moz-filter: $filter$;
filter: $filter$;
``
\end
\define transition(transition)
``
-webkit-transition: $transition$;
-moz-transition: $transition$;
transition: $transition$;
``
\end
\define transform-origin(origin)
``
-webkit-transform-origin: $origin$;
-moz-transform-origin: $origin$;
transform-origin: $origin$;
``
\end
\define background-linear-gradient(gradient)
``
background-image: linear-gradient($gradient$);
background-image: -o-linear-gradient($gradient$);
background-image: -moz-linear-gradient($gradient$);
background-image: -webkit-linear-gradient($gradient$);
background-image: -ms-linear-gradient($gradient$);
``
\end
\define column-count(columns)
``
-moz-column-count: $columns$;
-webkit-column-count: $columns$;
column-count: $columns$;
``
\end
\procedure datauri(title)
<$macrocall $name="makedatauri" type={{{ [<title>get[type]] }}} text={{{ [<title>get[text]] }}} _canonical_uri={{{ [<title>get[_canonical_uri]] }}}/>
\end
\procedure if-sidebar(text)
<$reveal state="$:/state/sidebar" type="match" text="yes" default="yes"><<text>></$reveal>
\end
\procedure if-no-sidebar(text)
<$reveal state="$:/state/sidebar" type="nomatch" text="yes" default="yes"><<text>></$reveal>
\end
\procedure if-background-attachment(text)
<$reveal state="$:/themes/tiddlywiki/vanilla/settings/backgroundimage" type="nomatch" text=""><<text>></$reveal>
\end