-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Jermolene
wants to merge
147
commits into
master
Choose a base branch
from
colour-improvements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+9,762
−456
Draft
Changes from all commits
Commits
Show all changes
147 commits
Select commit
Hold shift + click to select a range
fb9c0d6
Replace 12 year old CSS colour parsing library
Jermolene 93d1c05
Include colour.js license and mark version number
Jermolene 467a1a4
Introduce wikify operator
Jermolene a23ee16
Rewrite colour macro as a function
Jermolene e1e73d2
Merge branch 'master' into colour-improvements
Jermolene 1e5c69e
Fix typo
Jermolene 4af573a
Fix nested colour definitions
Jermolene 96b85ed
Fix up the tests
Jermolene d372729
Add colour-lighten and colour-darken operators
Jermolene b5a22e3
Remove obsolete comment
Jermolene fc36941
Improve colour palette switcher with previews
Jermolene 151f61a
Palette chooser styling tweaks
Jermolene 4445111
Merge branch 'master' into colour-improvements
Jermolene 4f2754d
Merge branch 'master' into colour-improvements
Jermolene bc0fde6
Fix palette chooser when displayed in "Tools" dropdown
Jermolene 85fa913
Merge branch 'master' into colour-improvements
Jermolene a8fb071
Add expertimental colour-oklch operator
Jermolene 81b7bb4
Merge branch 'master' into colour-improvements
Jermolene ff5c846
Indentation for palette switcher
Jermolene 23eccd1
Merge branch 'master' into colour-improvements
Jermolene c607440
Restore default styling for chosen chooser item
Jermolene 348f717
Remove logging
Jermolene c3ce9ca
Testing Netlify CI
Jermolene a4d9303
Testing CI
Jermolene 250e57c
Remove wikify operator and refactor palette preview
Jermolene 1be89a2
Make preview templates tag driven and extensible
Jermolene f889157
Introduce new static palette architecture
Jermolene 4e2f2be
Avoid redefining the colour function by adding a configuration variable
Jermolene b54d56e
Support for imported palettes
Jermolene 297ae7e
Fix preview of filtered palettes
Jermolene 38d5daa
Improve chooser chosen item highlight
Jermolene bad9517
Another fix for filtered palette previews
Jermolene 46da161
Add aria labels to palette switcher
Jermolene 1db8cf7
Merge branch 'master' into colour-improvements
Jermolene ad1b0fd
Palette tweaks
Jermolene 21cd3b8
Merge branch 'master' into colour-improvements
Jermolene 7de5f40
Merge branch 'master' into colour-improvements
Jermolene c2ee072
Merge branch 'master' into colour-improvements
Jermolene 3faf9ba
Fix previews of filtered palettes
Jermolene 8b59b61
Palette tweaks
Jermolene 809465b
Merge branch 'master' into colour-improvements
Jermolene cfabc92
Update contrastcolour macro to use color.js
Jermolene b2d0c22
Componentise more preview components
Jermolene 32ac671
Add alert preview
Jermolene b0828cc
Add notification preview
Jermolene 3507b0f
Fix filtered palette previews
Jermolene 84bef54
Docs for colour-oklch operator
Jermolene 76f2dec
Start fixing the TwentyTwenties palettes
Jermolene aa69c3a
Add colour-contrast operator
Jermolene cd5bbcd
Add contrast checks to TwentyTwenties palette
Jermolene 9efcad9
Display test results at the bottom of the palette switcher
Jermolene fc695e7
Merge branch 'master' into colour-improvements
Jermolene 6a66c49
Merge branch 'master' into colour-improvements
Jermolene 6fe16bc
Fix colour for site title
Jermolene 5a6eea7
Make the alert and notification previews be optional
Jermolene b1fcb18
Refactor for clearer variable names
Jermolene 1df0ac4
Refactor colour-oklch operator to colour-set-oklch
Jermolene ae1d9f5
Add colour-get-oklch operator
Jermolene c1e36a1
Add colour-interpolate operator
Jermolene 2640406
Include contrast value in contrast errors
Jermolene 3c44532
Barebones docs for colour spaces
Jermolene 2685fa7
Improvements to TwentyTwenties palettes
Jermolene 2eee3bf
Merge branch 'master' into colour-improvements
Jermolene 2558dc0
TwentyTwenties palette: use interpolation
Jermolene 6a06df7
Fix palette switcher
Jermolene b90b449
Use interpolation to derive colours
Jermolene c02c825
Add a primitive custom palette editor
Jermolene 5d1cf25
Add best contrast operator
Jermolene 6b39d6a
Fix editing colours that are not in 6 digit hex format
Jermolene d1ce548
Download button should use palette colours
Jermolene a429306
Clarify method name
Jermolene 2cbd108
Fix more TwentyTwenties entries
Jermolene bd4b3e4
Fix some old-style palette references
Jermolene 28167ad
Add a palette that automatically switches between dark and light
Jermolene 2b0c634
Refactor actions for recompiling current palette
Jermolene 69363bf
Palette manager should recompile palette on edits
Jermolene 2edcf0f
Refactor TwentyTwenties editor
Jermolene 55d9e92
Edit text widget shouldn't fully refresh when default attribute changes
Jermolene c75f50e
Fix palette switcher used in the sidebar
Jermolene 3614236
Paldette and style tweaks
Jermolene 62fb916
Merge branch 'master' into colour-improvements
Jermolene 9681b0d
Merge branch 'master' into colour-improvements
Jermolene 0baf395
Merge background actions and media tracker from #8555
Jermolene 28c1e77
Make sure rootwidget is available before background actions start
Jermolene 9588b7f
Autocompile palettes when they change
Jermolene 407e58f
Add a basic dark palette
Jermolene 8c619fd
Compile palette at startup
Jermolene 0dfde06
Detect darkmode at startup
Jermolene 7513e44
Allow text editor type=color for colours not in hex RGB format
Jermolene 3ea7cd3
Palette editors no longer need to manually recompile the palette
Jermolene 0fd5b04
Merge branch 'master' into colour-improvements
Jermolene 8957424
Start adding tests for palette operations
Jermolene d2bbc56
Move modern palettes to correct directory
Jermolene 317e124
Introduce an improved but temporary cache invalidation method for pal…
Jermolene 0c8aad4
Replace accumulate-palette-entries with new changecount filter
Jermolene efcd239
Merge branch 'master' into colour-improvements
Jermolene 546e438
Allow background actions to be scoped by platform
Jermolene effeed7
Remove extraneous logging
Jermolene c1fd82f
Minor cleanups
Jermolene 139b61f
Proper recursion detection for palettes
Jermolene 22cf3b2
Remove infinite loop that was added for testing
Jermolene a6a91d4
Restore accidentally deleted field
Jermolene a366d62
Include tiddler borders in preview
Jermolene 431149d
Introduce dynamic colour scheme mechanism
Jermolene 6970ac2
Typo
Jermolene a053f03
Remove logging
Jermolene c6bb2b5
Rethink palette manager
Jermolene c7f9dbf
Compile colour scheme handling
Jermolene 30a7d61
Easier for development if the prerelease uses the tw5.com palette
Jermolene 0ee2f28
Set colour scheme property of root element
Jermolene 2e5a988
Clarify comment
Jermolene a5c4d90
Refactor palette switcher a little
Jermolene 38865a4
Palette should autocompile when the palette tiddler itself changes
Jermolene 998d5c8
The lingo macro shouldn't mess with currentTiddler
Jermolene 6e4d7aa
Give the AutoToggle palette a custom editor
Jermolene f9e4dd8
Rename custom palette editor to custom palette settings
Jermolene 4d06ecd
Only allow palettes to import palettes of the same type
Jermolene 796c33b
Refactor some variable names
Jermolene 0d9ab2e
Remove unneeded scheme processing
Jermolene 961b26a
Get rid of palette-types...
Jermolene 4fe90a6
Add VanillaCherry palette
Jermolene 4c21664
Introduce background palettes for plugins
Jermolene bfea62b
The tags macros do not actually need access to the palette
Jermolene 1f4f164
Take advantage of compiled palettes
Jermolene eba73ee
Missed off 961b26a984fd93f94b8e2686771bc2e59f03c745
Jermolene 7c49382
Refactor the palette preview macros into a generic widget
Jermolene e87aaff
Add tabs to the preview
Jermolene 4665bab
AutoToggle should default to light mode so that static exports are li…
Jermolene 7df9878
Move generic tests into a background palette
Jermolene d8dfc10
Typo
Jermolene 7da70ec
Add tabs and recent list to the sidebar
Jermolene d2204ae
Fill in some missing palette entries
Jermolene 92b7819
Fix Codemirror colour palette fallbacks
Jermolene 71a144f
Typo
Jermolene 28935a5
Add hue adjuster to colour-interpolate operator
Jermolene 611adad
Add apply filter run prefix
Jermolene 83c6223
Refactor the interpolate operator so it can be used with the range op…
Jermolene 067a1a2
Move sample background item out of the core
Jermolene 422b092
Don't need consent banner anymore
Jermolene 09f8ab9
Move from v5.3.7 -> v5.4.0
Jermolene 49969a2
Docs for apply filter run prefix
Jermolene 377856c
Add temporary guide tiddler at the top
Jermolene 0037813
Background action demos should require explicit enabling
Jermolene d7df7ed
Introduce tf.colour function to make palette entries more concise
Jermolene 8b05b72
Merge branch 'master' into colour-improvements
Jermolene 2028420
Fixes suggested by @pmario
Jermolene 059e439
Merge branch 'master' into colour-improvements
Jermolene File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/*\ | ||
title: $:/core/modules/background-actions.js | ||
type: application/javascript | ||
module-type: global | ||
|
||
Class to dispatch actions when filters change | ||
|
||
\*/ | ||
(function(){ | ||
|
||
/*jslint node: true, browser: true */ | ||
/*global $tw: false */ | ||
"use strict"; | ||
|
||
function BackgroundActionDispatcher(filterTracker,wiki) { | ||
var self = this; | ||
this.filterTracker = filterTracker; | ||
this.wiki = wiki; | ||
this.nextTrackedFilterId = 1; | ||
this.trackedFilters = Object.create(null); // Hashmap by id | ||
// Track the filter for the background actions | ||
this.filterTracker.track({ | ||
filterString: "[all[tiddlers+shadows]tag[$:/tags/BackgroundAction]!is[draft]]", | ||
fnEnter: function fnEnter(title) { | ||
return self.trackFilter(title); | ||
}, | ||
fnLeave: function fnLeave(title,enterValue) { | ||
self.untrackFilter(enterValue); | ||
}, | ||
fnChange: function fnChange(title,enterValue) { | ||
self.untrackFilter(enterValue); | ||
return self.trackFilter(title); | ||
}, | ||
fnProcess: function fnProcess(changes) { | ||
self.process(changes); | ||
} | ||
}); | ||
} | ||
|
||
BackgroundActionDispatcher.prototype.trackFilter = function(title) { | ||
var tiddler = this.wiki.getTiddler(title), | ||
id = this.nextTrackedFilterId++, | ||
tracker = new BackgroundActionTracker({ | ||
wiki: this.wiki, | ||
title: title, | ||
trackFilter: tiddler.fields["track-filter"], | ||
actions: tiddler.fields.text | ||
}); | ||
this.trackedFilters[id] = tracker; | ||
return id; | ||
}; | ||
|
||
BackgroundActionDispatcher.prototype.untrackFilter = function(enterValue) { | ||
var tracker = this.trackedFilters[enterValue]; | ||
if(tracker) { | ||
tracker.destroy(); | ||
} | ||
delete this.trackedFilters[enterValue]; | ||
}; | ||
|
||
BackgroundActionDispatcher.prototype.process = function(changes) { | ||
for(var id in this.trackedFilters) { | ||
this.trackedFilters[id].process(changes); | ||
} | ||
}; | ||
|
||
/* | ||
Represents an individual tracked filter. Options include: | ||
wiki: wiki to use | ||
title: title of the tiddler being tracked | ||
trackFilter: filter string to track changes | ||
actions: actions to be executed when the filter changes | ||
*/ | ||
function BackgroundActionTracker(options) { | ||
var self = this; | ||
this.wiki = options.wiki; | ||
this.title = options.title; | ||
this.trackFilter = options.trackFilter; | ||
this.actions = options.actions; | ||
this.filterTracker = new $tw.FilterTracker(this.wiki); | ||
this.hasChanged = false; | ||
this.trackerID = this.filterTracker.track({ | ||
filterString: this.trackFilter, | ||
fnEnter: function(title) { | ||
self.hasChanged = true; | ||
}, | ||
fnLeave: function(title,enterValue) { | ||
self.hasChanged = true; | ||
}, | ||
fnProcess: function(changes) { | ||
if(self.hasChanged) { | ||
self.hasChanged = false; | ||
console.log("Processing background action",self.title); | ||
var tiddler = self.wiki.getTiddler(self.title), | ||
doActions = true; | ||
if(tiddler && tiddler.fields.platforms) { | ||
doActions = false; | ||
var platforms = $tw.utils.parseStringArray(tiddler.fields.platforms); | ||
if(($tw.browser && platforms.indexOf("browser") !== -1) || ($tw.node && platforms.indexOf("node") !== -1)) { | ||
doActions = true; | ||
} | ||
} | ||
if(doActions) { | ||
self.wiki.invokeActionString( | ||
self.actions, | ||
null, | ||
{ | ||
currentTiddler: self.title | ||
},{ | ||
parentWidget: $tw.rootWidget | ||
} | ||
); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
BackgroundActionTracker.prototype.process = function(changes) { | ||
this.filterTracker.handleChangeEvent(changes); | ||
}; | ||
|
||
BackgroundActionTracker.prototype.destroy = function() { | ||
this.filterTracker.untrack(this.trackerID); | ||
}; | ||
|
||
exports.BackgroundActionDispatcher = BackgroundActionDispatcher; | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/*\ | ||
title: $:/core/modules/filter-tracker.js | ||
type: application/javascript | ||
module-type: global | ||
|
||
Class to track the results of a filter string | ||
|
||
\*/ | ||
(function(){ | ||
|
||
/*jslint node: true, browser: true */ | ||
/*global $tw: false */ | ||
"use strict"; | ||
|
||
function FilterTracker(wiki) { | ||
this.wiki = wiki; | ||
this.trackers = []; | ||
this.nextTrackerId = 1; | ||
} | ||
|
||
FilterTracker.prototype.handleChangeEvent = function(changes) { | ||
this.processTrackers(); | ||
this.processChanges(changes); | ||
}; | ||
|
||
/* | ||
Add a tracker to the filter tracker. Returns null if any of the parameters are invalid, or a tracker id if the tracker was added successfully. Options include: | ||
filterString: the filter string to track | ||
fnEnter: function to call when a title enters the filter results. Called even if the tiddler does not actually exist. Called as (title), and should return a truthy value that is stored in the tracker as the "enterValue" | ||
fnLeave: function to call when a title leaves the filter results. Called as (title,enterValue) | ||
fnChange: function to call when a tiddler changes in the filter results. Only called for filter results that identify a tiddler or shadow tiddler. Called as (title,enterValue), and may optionally return a replacement enterValue | ||
fnProcess: function to call each time the tracker is processed, after any enter, leave or change functions are called. Called as (changes) | ||
*/ | ||
FilterTracker.prototype.track = function(options) { | ||
// Add the tracker details | ||
var tracker = { | ||
id: this.nextTrackerId++, | ||
filterString: options.filterString, | ||
fnEnter: options.fnEnter, | ||
fnLeave: options.fnLeave, | ||
fnChange: options.fnChange, | ||
fnProcess: options.fnProcess, | ||
previousResults: [], // Results from the previous time the tracker was processed | ||
resultValues: {} // Map by title to the value returned by fnEnter | ||
}; | ||
this.trackers.push(tracker); | ||
// Process the tracker | ||
this.processTracker(this.trackers.length - 1); | ||
return tracker.id; | ||
}; | ||
|
||
FilterTracker.prototype.untrack = function(id) { | ||
for(var t=0; t<this.trackers.length; t++) { | ||
if(this.trackers[t].id === id) { | ||
this.trackers.splice(t,1); | ||
break; | ||
} | ||
} | ||
}; | ||
|
||
FilterTracker.prototype.processTrackers = function() { | ||
for(var t=0; t<this.trackers.length; t++) { | ||
this.processTracker(t); | ||
} | ||
}; | ||
|
||
FilterTracker.prototype.processTracker = function(index) { | ||
var tracker = this.trackers[index]; | ||
var results = []; | ||
// Evaluate the filter and remove duplicate results | ||
$tw.utils.each(this.wiki.filterTiddlers(tracker.filterString),function(title) { | ||
$tw.utils.pushTop(results,title); | ||
}); | ||
// Process the newly entered results | ||
$tw.utils.each(results,function(title) { | ||
if(tracker.previousResults.indexOf(title) === -1 && !tracker.resultValues[title] && tracker.fnEnter) { | ||
tracker.resultValues[title] = tracker.fnEnter(title) || true; | ||
} | ||
}); | ||
// Process the results that have just left | ||
$tw.utils.each(tracker.previousResults,function(title) { | ||
if(results.indexOf(title) === -1 && tracker.resultValues[title] && tracker.fnLeave) { | ||
tracker.fnLeave(title,tracker.resultValues[title]); | ||
delete tracker.resultValues[title]; | ||
} | ||
}); | ||
// Update the previous results | ||
tracker.previousResults = results; | ||
}; | ||
|
||
FilterTracker.prototype.processChanges = function(changes) { | ||
for(var t=0; t<this.trackers.length; t++) { | ||
var tracker = this.trackers[t]; | ||
$tw.utils.each(changes,function(change,title) { | ||
if(title && tracker.previousResults.indexOf(title) !== -1 && tracker.fnChange) { | ||
// Call the change function and if it doesn't return a value then keep the old value | ||
tracker.resultValues[title] = tracker.fnChange(title,tracker.resultValues[title]) || tracker.resultValues[title]; | ||
} | ||
}); | ||
if(tracker.fnProcess) { | ||
tracker.fnProcess(changes); | ||
} | ||
} | ||
}; | ||
|
||
exports.FilterTracker = FilterTracker; | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/*\ | ||
title: $:/core/modules/filterrunprefixes/apply.js | ||
type: application/javascript | ||
module-type: filterrunprefix | ||
|
||
Filter run prefix to make input titles available as variables when evaluating the filter run | ||
|
||
\*/ | ||
(function(){ | ||
|
||
/*jslint node: true, browser: true */ | ||
/*global $tw: false */ | ||
"use strict"; | ||
|
||
exports.apply = function(operationSubFunction) { | ||
return function(results,source,widget) { | ||
source = widget.wiki.makeTiddlerIterator([]); | ||
var variables = {}, | ||
counter = 1; | ||
results.each(function(title) { | ||
variables["$" + counter] = title; | ||
counter++; | ||
}); | ||
results.clear(); | ||
results.pushTop(operationSubFunction(source,widget.makeFakeWidgetWithVariables(variables))); | ||
}; | ||
}; | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*\ | ||
title: $:/core/modules/filters/changecount.js | ||
type: application/javascript | ||
module-type: filteroperator | ||
|
||
Filter operator for retrieving the changecount for each title in the list. | ||
|
||
\*/ | ||
(function(){ | ||
|
||
/*jslint node: true, browser: true */ | ||
/*global $tw: false */ | ||
"use strict"; | ||
|
||
/* | ||
Export our filter function | ||
*/ | ||
exports.changecount = function(source,operator,options) { | ||
var results = []; | ||
source(function(tiddler,title) { | ||
results.push(options.wiki.getChangeCount(title) + ""); | ||
}); | ||
return results; | ||
}; | ||
|
||
})(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this counter
this.nextTrackedFilterId
should be namedthis.nextTrackedFilterIdx
...Idx
for index orCnt
for counter. Just a thought. I did not single step the function yetThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @pmario. These ids are intended to be opaque to client code; there is no semantics in incrementing or decrementing them, they're just used as an identifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok