Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colour handling improvements #8702

Draft
wants to merge 62 commits into
base: master
Choose a base branch
from
Draft

Colour handling improvements #8702

wants to merge 62 commits into from

Conversation

Jermolene
Copy link
Member

@Jermolene Jermolene commented Oct 25, 2024

Introduction

We get persistent of feedback that the visual aesthetic of TiddlyWiki is old fashioned and dull. It's fair criticism: the default look and feel was intended to be muted so that the users content took centre stage but has ended up flat and lifeless.

The ultimate goal of this PR is to allow end users to easily devise their own colour schemes that match their tastes and work harmoniously together.

This will be accomplished with a new user interface that is presented in the empty "GettingStarted" tiddler, and in the control panel. The UI would have sliders and switches for the user to express their taste: colourful vs. muted, dark vs. light, saturated vs. unsaturated.

Underneath those controls would be displayed a grid of 9 random palettes generated to match the parameters. The user can choose one of them and either select it, or choose to use it as the basis to generate further variants.

The underlying mechanism is based on the idea of palettes defined as a small number of base colours, with rules for dynamically generating the full palette by dynamically lightening, darkening or otherwise manipulating an existing colour. This approach is similar to that of the colour system in Android for example.

This PR is highly experimental. It may not be merged in this form; I have already started cherry picking parts into separate PRs.

Colour Manipulation

We need a colour manipulation library that can calculate variants of colours. Only color.js met the requirements of being able to work with P3 colours and the OKLCH colour space. It also includes a CSS colour string parser which can replace the simple one that TiddlyWiki has always incorporated.

Static Palette Entries

The key idea underpinning these changes is a fundamental change to the way that TiddlyWiki handles palettes. At the moment, palette entries are named items that can contain either a CSS colour string, a CSS colour token like "inherit", or use the <<colour>> macro to reference another colour palette entry. Thus, palette entries have to be wikified before they can be used. This has turned out to be extremely limiting.

The idea of static palettes is that at the point of switching to a new palette, the colours within it are "compiled" to raw CSS colour values (typically but not necessarily in #rrggbbaa format). This allows palette entries to be used directly, without the requirement to wikify them.

The static palette is created in a new system tiddler $:/temp/palette-colours by an action procedure that is invoked at startup and when switching to a new palette.

The primary backwards compatibility issue is that any existing code that switches palettes by writing to the tiddler $:/palette will no longer cause a palette change because $:/temp/palette-colours will not have been updated. Code that uses the core palette switcher will continue to work properly.

This change will also allow us to change the <<colour>> procedure to be a function, which will allow it to be used as the value for a style attribute:

<div style.background=<<colour tiddler-background>>>

Modern Palettes

This PR also introduces a new type of palette referred to as "modern" which is exactly like the existing palette except that the entries are defined as functions that must be evaluated, rather than wikitext that must be wikified.

This makes it possible to create palettes that reference and modify other colours. For example:

tiddler-background: [<colour background>colour-darken[0.5]colour-saturate[2]]

Colour Palette Preview

Something I've wanted for a long time is to improve the colour palette chooser to include a preview. It is not finished yet, but has turned out to be quite easy and very effective:

image

References

Progress

  • Added wikify operator with tests
  • Removed wikify operator to separate PR Add wikify operator #8730
  • Integrated color.js
  • Replace existing core CSS colour parser with the equivalent functionality from color.js
  • Convert and then reverted changing the colour macro to a function
  • Add darken and lighten filter operators with tests
  • Enhanced colour palette preview
  • Extended wikitext test runner to be able to unpack plugins

The replacement library from https://colorjs.io/ is much, much larger but I think we can develop a custom build that uses treeshaking to whittle the code down to the bits that we need. @linonetwo does that sound feasible?

I intend the explore further improvements but I wanted to start by establishing a library that can do modern P3 and OKLCH colour calculations.
Really just syntactic sugar for the wikify widget
Using the new wikify operator.

Currently has a bug whereby redirected colours (like "tiddler-background") do not work. Direct colours like "background" do work.

Note the hacks needed to makeFakeWidgetWithVariables work
Copy link

Confirmed: Jermolene has already signed the Contributor License Agreement (see contributing.md)

@@ -2853,19 +2867,22 @@ a.tc-tiddlylink.tc-plugin-info:hover > .tc-plugin-info-chunk .tc-plugin-info-sta
color: <<colour foreground>>;
}

.tc-chosen > .tc-tiddlylink:before {
Copy link
Member

@pmario pmario Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we need to keep this configuration for backwards compatibility. We can add a "deprecated" comment, but plugin authors may use these styles.

I'll need to make some more tests, with the palette-manager edition.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jermolene -- The tools-buttons: theme, layout, storyview and palette use this CSS. So IMO we can not remove it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the "chosen" indicators fail now.

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pmario, fixed in c607440

@@ -2,15 +2,18 @@ title: $:/snippets/paletteswitcher

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add indentation, so it's easier to read

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point will do

"fields": {
"type": "application/javascript",
"title": "$:/core/modules/utils/dom/color.js",
"module-type": "library"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should add 2 more fields: version: 0.5.2 and repo: https://github.com/color-js/color.js to make it easier for us to maintain

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pmario if we were going to add those fields then we should do so consistently for all the 3rd party libraries in the core.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be a good idea and we have to start somewhere.

@kookma
Copy link
Contributor

kookma commented Nov 4, 2024

Is there a demo to test colour handling improvement?

@Jermolene
Copy link
Member Author

Is there a demo to test colour handling improvement?

Hi @kookma I've posted a preview to tiddlyhost

These filtered palettes are still just experiments with the techniques, and not yet a serious palette
I think I might be building a programming language for writing palettes...
Still a work in progress, but getting more coherent
@kookma
Copy link
Contributor

kookma commented Dec 16, 2024

Hi Jeremy,
Is there updated version of Colour handling to test?

Thank you

For example, this filter expression will get the lightness of the colour current page background colour:

```
[function[colour],[page-background]colour-get-oklch:l[]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did test this: [function[colour],[page-background]colour-get-oklch:h[]] -> RSOD See suffix :h

Click for screenshot

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants