From 9efcad936007338d2123e295a97b42734b2b3355 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 19 Nov 2024 09:09:11 +0000 Subject: [PATCH] Display test results at the bottom of the palette switcher --- core/palette-templates/TwentyTwenties.tid | 4 +++- core/wiki/macros/CSS.tid | 6 ++++++ core/wiki/paletteswitcher.tid | 2 ++ core/wiki/palettetests.tid | 19 +++++++++++++++++++ editions/prerelease/tiddlers/palette.tid | 2 +- 5 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 core/wiki/palettetests.tid diff --git a/core/palette-templates/TwentyTwenties.tid b/core/palette-templates/TwentyTwenties.tid index 1bc7735c3b8..18558b4ffa8 100644 --- a/core/palette-templates/TwentyTwenties.tid +++ b/core/palette-templates/TwentyTwenties.tid @@ -18,7 +18,9 @@ base-secondary: rgb(236, 212, 58) base-tertiary: rgb(135, 239, 70) # Contrast tests -?background-foreground-contrast: [function[colour],[background]] [function[colour],[base-background]] +[colour-contrast:DeltaPhi[]compare:number:gt[25]then[ok]else[Foreground/background contrast is too low]] +?background-foreground-contrast: [tf.check-colour-contrast[background],[foreground],[125]] +?alert-contrast: [tf.check-colour-contrast[alert-background],[foreground],[25]] +?code-contrast: [tf.check-colour-contrast[code-background],[code-foreground],[25]] # Colour definitions alert-background: [function[colour],[base-secondary]colour-oklch:l[0.9]] diff --git a/core/wiki/macros/CSS.tid b/core/wiki/macros/CSS.tid index f367d11f8db..59826452d08 100644 --- a/core/wiki/macros/CSS.tid +++ b/core/wiki/macros/CSS.tid @@ -2,6 +2,8 @@ title: $:/core/macros/CSS tags: $:/tags/Macro \procedure actions-compile-palette-filtered(tempPalette,outputTitle) + +\function colour(name) [getindex] :else[get[palette-import]getindex] :map[subfilterjoin[ ]] <$let tv-palette-name=<> @@ -77,6 +79,10 @@ tags: $:/tags/Macro [function[colour],] \end color +\function tf.check-colour-contrast(paletteEntryA,paletteEntryB,threshold) +[function[colour],] [function[colour],] +[colour-contrast:DeltaPhi[]compare:number:gtthen[ok]] :else[addsuffix[/]addsuffixaddsuffix[ contrast is too low]] +\end tf.check-colour-contrast + \define box-shadow(shadow) `` -webkit-box-shadow: $shadow$; diff --git a/core/wiki/paletteswitcher.tid b/core/wiki/paletteswitcher.tid index bdde81e4b09..ced304b7ba7 100644 --- a/core/wiki/paletteswitcher.tid +++ b/core/wiki/paletteswitcher.tid @@ -24,3 +24,5 @@ title: $:/snippets/paletteswitcher + +{{$:/snippets/palettetests}} diff --git a/core/wiki/palettetests.tid b/core/wiki/palettetests.tid new file mode 100644 index 00000000000..b7bd24d69ff --- /dev/null +++ b/core/wiki/palettetests.tid @@ -0,0 +1,19 @@ +title: $:/snippets/palettetests + +<$let failureCount={{{ [[$:/temp/palette-colours]indexes[]prefix[?]] :filter[[$:/temp/palette-colours]getindex!match[ok]] +[count[]] }}}> + +<%if [compare:number:gt[0]] %> + +Palette test failures: <$text text=<>/> + +<$list filter="[[$:/temp/palette-colours]indexes[]prefix[?]sort[]]" variable="name"> + <%if [[$:/temp/palette-colours]getindex!match[ok]] %> +
+ ''<$text text={{{ [removeprefix[?]] }}}/>'': <$text text={{{ [[$:/temp/palette-colours]getindex] }}}/> +
+ <%endif%> + + +<%endif%> + + diff --git a/editions/prerelease/tiddlers/palette.tid b/editions/prerelease/tiddlers/palette.tid index afd78912b7a..9cd6f441c64 100644 --- a/editions/prerelease/tiddlers/palette.tid +++ b/editions/prerelease/tiddlers/palette.tid @@ -1,3 +1,3 @@ title: $:/palette -$:/palettes/Vanilla \ No newline at end of file +$:/palettes/TwentyTwenties \ No newline at end of file