mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-30 05:19:57 +00:00
Add colour-lighten and colour-darken operators
This commit is contained in:
parent
96b85edfa2
commit
d372729ed0
41
core/modules/filters/colour-ops.js
Normal file
41
core/modules/filters/colour-ops.js
Normal file
@ -0,0 +1,41 @@
|
||||
/*\
|
||||
title: $:/core/modules/filters/colour-ops.js
|
||||
type: application/javascript
|
||||
module-type: filteroperator
|
||||
|
||||
Filter operators for colour operations
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var Color = require("$:/core/modules/utils/dom/color.js").Color;
|
||||
|
||||
exports["colour-lighten"] = makeColourOperator(function (c, operator, operands) {
|
||||
return c.lighten($tw.utils.parseNumber(operator.operand));
|
||||
});
|
||||
|
||||
exports["colour-darken"] = makeColourOperator(function (c, operator, operands) {
|
||||
return c.darken($tw.utils.parseNumber(operator.operand));
|
||||
});
|
||||
|
||||
function makeColourOperator(fn) {
|
||||
return function (source, operator, options) {
|
||||
var results = [];
|
||||
source(function (tiddler, title) {
|
||||
var c = $tw.utils.parseCSSColorObject(title);
|
||||
if (c) {
|
||||
c = fn(c, operator, options);
|
||||
results.push(c.display().toString());
|
||||
} else {
|
||||
results.push("");
|
||||
}
|
||||
});
|
||||
return results;
|
||||
};
|
||||
}
|
||||
|
||||
})();
|
@ -12,14 +12,13 @@ Color.js related utilities
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var Color = require("$:/core/modules/utils/dom/color.js").Color;
|
||||
|
||||
/*
|
||||
For backwards compatibility
|
||||
*/
|
||||
exports.parseCSSColor = function(colourString) {
|
||||
var Color = require("$:/core/modules/utils/dom/color.js").Color,
|
||||
c = null;
|
||||
try {
|
||||
c = new Color(colourString);
|
||||
} catch(e) {
|
||||
// Do nothing on an error
|
||||
}
|
||||
var c = exports.parseCSSColorObject(colourString);
|
||||
if(c) {
|
||||
var rgb = c.srgb;
|
||||
return [rgb[0],rgb[1],rgb[2],c.alpha];
|
||||
@ -28,4 +27,19 @@ exports.parseCSSColor = function(colourString) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Preferred way to parse a Color.js colour
|
||||
*/
|
||||
exports.parseCSSColorObject = function(colourString) {
|
||||
var Color = require("$:/core/modules/utils/dom/color.js").Color,
|
||||
c = null;
|
||||
try {
|
||||
c = new Color(colourString);
|
||||
} catch(e) {
|
||||
// Return null if there is an error
|
||||
}
|
||||
return c;
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -0,0 +1,18 @@
|
||||
title: Operators/Colour/ColourDarken
|
||||
description: Darken colour function
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\parsermode inline
|
||||
\import [subfilter{$:/core/config/GlobalImportFilter}]
|
||||
<$text text={{{ [subfilter{Filter}] }}}/>
|
||||
+
|
||||
title: Filter
|
||||
|
||||
[function[colour],[primary]colour-darken[0.5]]
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
#0f1d77
|
@ -0,0 +1,18 @@
|
||||
title: Operators/Colour/ColourLighten
|
||||
description: Lighten colour function
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\parsermode inline
|
||||
\import [subfilter{$:/core/config/GlobalImportFilter}]
|
||||
<$text text={{{ [subfilter{Filter}] }}}/>
|
||||
+
|
||||
title: Filter
|
||||
|
||||
[function[colour],[primary]colour-lighten[0.5]]
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
#c6dbff
|
Loading…
Reference in New Issue
Block a user