dd / evolutioncms-snippets-ddcolortools
Converts the color to match the offset in tone, brightness, or saturation.
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:modxevo-snippet
Requires
- php: >=5.6.0
- dd/evolutioncms-libraries-ddtools: >=0.60.0
- dd/evolutioncms-snippets-ddgetdocumentfield: >=2.11.1
This package is auto-updated.
Last update: 2024-12-06 07:43:31 UTC
README
Converts the color to match the offset in tone, brightness, or saturation.
Requires
- PHP >= 5.6
- (MODX)EvolutionCMS.libraries.ddTools >= 0.60
- (MODX)EvolutionCMS.snippets.ddGetDocumentField >= 2.11.1
Installation
Manually
1. Elements → Snippets: Create a new snippet with the following data
- Snippet name:
ddColorTools
. - Description:
<b>3.2.1</b> Converts the color to match the offset in tone, brightness, or saturation.
. - Category:
Core
. - Parse DocBlock:
no
. - Snippet code (php): Insert content of the
ddColorTools_snippet.php
file from the archive.
2. Elements → Manage Files
- Create a new folder
assets/snippets/ddColorTools/
. - Extract the archive to the folder (except
ddColorTools_snippet.php
).
Using (MODX)EvolutionCMS.libraries.ddInstaller
Just run the following PHP code in your sources or Console:
//Include (MODX)EvolutionCMS.libraries.ddInstaller require_once( $modx->getConfig('base_path') . 'assets/libs/ddInstaller/require.php' ); //Install (MODX)EvolutionCMS.snippets.ddColorTools \DDInstaller::install([ 'url' => 'https://github.com/DivanDesign/EvolutionCMS.snippets.ddColorTools', 'type' => 'snippet' ]);
- If
ddColorTools
is not exist on your site,ddInstaller
will just install it. - If
ddColorTools
is already exist on your site,ddInstaller
will check it version and update it if needed.
Parameters description
Input color
-
inputColor
- Desctription: Input color as HEX, HSL or HSB/HSV, with or without alpha-channel.
Case-insensitive.
Valid format examples:ffffff
#FFFFFF
#FFFFFFFF
hsl(0, 0%, 100%)
hsla(0, 0%, 100%)
HSL(0, 0, 100)
hsb(0, 0%, 100%)
hsba(0, 0%, 100%)
hsv(0, 0%, 100%)
hsva(0, 0%, 100%)
hsb(0, 0, 100)
hsv(0, 0, 100)
- Valid values:
string
- Required
- Desctription: Input color as HEX, HSL or HSB/HSV, with or without alpha-channel.
-
inputColor_docField
- Desctription: The name of the document field / TV which value is required to get.
If the parameter is passed then the input string will be taken from the field / TV andinputColor
will be ignored. - Valid values:
string
- Default value: —
- Desctription: The name of the document field / TV which value is required to get.
-
inputColor_docId
- Desctription: ID of the document which field/TV value is required to get.
inputColor_docId
equals the current document id sinceinputString_docId
is unset. - Valid values:
integer
- Default value: —
- Desctription: ID of the document which field/TV value is required to get.
Color modification
All parameters can contain the following special operators:
+
(e. g.+10
) — plus-
(e. g.-10
) — minusabs
— round to max or min valuer
— invert- without operator (e. g.
10
) — just set equal to
-
offset_h
- Desctription: Operations of the hue offset separated by commas.
- Valid values:
stringCommaSeparated
- Default value:
'+0'
-
offset_h[i]
- Desctription: Offset of the hue in degrees (
[-360; +360]
). - Valid values:
string
- Required
- Desctription: Offset of the hue in degrees (
-
offset_s
- Desctription: Operations of the saturation offset separated by commas.
- Valid values:
stringCommaSeparated
- Default value:
'+0'
-
offset_s[i]
- Desctription: Offset of the saturation in persents (
[-100; +100]
). - Valid values:
string
- Required
- Desctription: Offset of the saturation in persents (
-
offset_l
- Desctription: Operations of the lightness offset separated by commas.
- Valid values:
stringCommaSeparated
- Default value:
'+0'
-
offset_l[i]
- Desctription: Offset of the lightness in persents (
[-100; +100]
). - Valid values:
string
- Required
- Desctription: Offset of the lightness in persents (
-
offset_a
- Desctription: Operations of the alpha-channel offset separated by commas.
- Valid values:
stringCommaSeparated
- Default value:
'+0'
-
offset_a[i]
- Desctription: Offset of the alpha-channel in persents (
[-100; +100]
). - Valid values:
string
- Required
- Desctription: Offset of the alpha-channel in persents (
Output
-
result_outputFormat
- Desctription: Output color format.
Case-insensitive. - Valid values:
'hex'
'hsl'
'rgb'
- Default value:
'hsl'
- Desctription: Output color format.
-
result_tpl
- Desctription: Chunk to parse result.
Available placeholders:[+ddResult+]
— full color string[+ddH+]
— hue[+ddS+]
— saturation[+ddL+]
— lightness[+ddA+]
— alpha-channel[+ddIsDark+]
— is color dark (0
||1
)?
- Valid values:
stringChunkName
string
— use inline templates starting with@CODE:
- Default value: —
- Desctription: Chunk to parse result.
-
result_tpl_placeholders
- Desctription:
Additional data has to be passed into the
result_tpl
.
Nested objects and arrays are supported too:{"someOne": "1", "someTwo": "test" }
=>[+someOne+], [+someTwo+]
.{"some": {"a": "one", "b": "two"} }
=>[+some.a+]
,[+some.b+]
.{"some": ["one", "two"] }
=>[+some.0+]
,[+some.1+]
.
- Valid values:
stringJsonObject
— as JSONstringHjsonObject
— as HJSONstringQueryFormatted
— as Query string- It can also be set as a native PHP object or array (e. g. for calls through
$modx->runSnippet
):arrayAssociative
object
- Default value: —
- Desctription:
Additional data has to be passed into the
Examples
Set black or white font color depending on background color
We need black texts in light backgrounds and vice versa.
Let's pass background color as inputColor
to the snippet:
color: [[ddColorTools?
&inputColor=`#007cc3`
&result_tpl=`blackOrWhiteColor`
]];
Code of the blackOrWhiteColor
chunk:
hsl(0, 0%, [[ddIf?
&operand1=`[+ddIsDark+]`
&operator=`bool`
&trueChunk=`100`
&falseChunk=`0`
]]%)
Run the snippet through \DDTools\Snippet::runSnippet
without DB and eval
//Include (MODX)EvolutionCMS.libraries.ddTools require_once( $modx->getConfig('base_path') . 'assets/libs/ddTools/modx.ddtools.class.php' ); //Run (MODX)EvolutionCMS.snippets.ddColorTools \DDTools\Snippet::runSnippet([ 'name' => 'ddColorTools', 'params' => [ 'inputColor' => '#000000', 'result_tpl' => 'colorTpl' ] ]);