Skip to content

Commit

Permalink
Merge pull request #107 from zamsyt/main
Browse files Browse the repository at this point in the history
Re-add `hsl-split-decimal`
  • Loading branch information
mgmeyers authored Feb 14, 2023
2 parents 4cb0802 + 82e52b6 commit 29960ed
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ body.theme-dark.css-settings-manager { --accent: #2DB253; }

### `variable-color` formatting options

There are 7 formatting options:
There are 8 formatting options:

- `hex`

Expand Down Expand Up @@ -475,6 +475,23 @@ When `opacity` is set to `true`:
--accent-a: 1;
```

- `hsl-split-decimal`

```
--accent-h: 211;
--accent-s: 1;
--accent-l: 0.5;
```

When `opacity` is set to `true`:

```
--accent-h: 211;
--accent-s: 1;
--accent-l: 0.5;
--accent-a: 1;
```

## `color-gradient`

`color-gradient` outputs a fixed number of colors along a gradient between two existing color variables. A `format` attribute is also required. *Note: The `to` variable must be set in style settings for the gradient to be generated. Also, gradients will only be generated using colors defined under the current style settings `id`.*
Expand Down
1 change: 1 addition & 0 deletions src/SettingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export type ColorFormat =
| 'hsl'
| 'hsl-values'
| 'hsl-split'
| 'hsl-split-decimal'
| 'rgb'
| 'rgb-values'
| 'rgb-split'
Expand Down
27 changes: 27 additions & 0 deletions src/SettingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,33 @@ function generateColorVariables(

return out;
}
case 'hsl-split-decimal': {
const hsl = parsedColor.hsl();
const h = isNaN(hsl[0]) ? 0 : hsl[0];
const out = [
{
key: `${key}-h`,
value: h.toString(),
},
{
key: `${key}-s`,
value: hsl[1].toString(),
},
{
key: `${key}-l`,
value: hsl[2].toString(),
},
...alts,
];

if (opacity)
out.push({
key: `${key}-a`,
value: parsedColor.alpha().toString(),
});

return out;
}
case 'rgb':
return [
{
Expand Down

0 comments on commit 29960ed

Please sign in to comment.