Skip to content
This repository was archived by the owner on Aug 25, 2020. It is now read-only.

Commit d2372b5

Browse files
committed
feat: move ColorService methods to standalone functions
1 parent 92157b3 commit d2372b5

50 files changed

Lines changed: 515 additions & 461 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -264,25 +264,21 @@ constructor(private styler: StylerComponent) {
264264
}
265265
```
266266

267-
## Services
267+
## Helpers
268268

269-
### `StylerDefService`
269+
### Styles definition
270270

271-
* `pick(state: string, styles, default?: string)` - returns styles[state|default]
272-
* `toggle(state: boolean, styles)` - returns styles if state is true
273-
* `merge` - js deepMerge, needed if states have $nest props
271+
* `defPick(state: string, styles, default?: string)` - returns styles[state|default]
272+
* `defPick(state: boolean, styles)` - returns styles if state is true
273+
* `defPick` - js deepMerge, needed if states have $nest props
274274

275-
### `StylerColorService`
275+
### Colors
276276

277-
Service for color manipulating.
277+
Helpers for color manipulating.
278278

279279
```ts
280-
import { StylerColorService } from '@ngx-kit/styler';
281280
...
282-
constructor(private color: StylerColorService) {
283-
}
284-
...
285-
background: this.darken(0.2, someColorVar),
281+
background: darken(0.2, someColorVar),
286282
```
287283

288284
* `adjustHue`

package/src/compiler/compiler.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DOCUMENT } from '@angular/common';
22
import { Inject, Injectable } from '@angular/core';
33
import { ɵSharedStylesHost as SharedStylesHost } from '@angular/platform-browser';
4-
import { processAutoPx } from '../helpers/process-auto-px';
4+
import { processAutoPx } from './process-auto-px';
55
import { autoPx } from '../meta/compiler';
66
import { StyleDef } from '../meta/def';
77
import { Style } from '../meta/style';

package/src/compiler/props/border.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { processAutoPx } from '../../helpers/process-auto-px';
1+
import { processAutoPx } from '../process-auto-px';
22
import { CssBorder, CssBorderProps, CssBorderSmart } from '../../meta/style';
33
import { isObject } from '../../utils/is-object';
44
import { isUndefined } from '../../utils/is-undefined';

package/src/compiler/props/margin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { processAutoPx } from '../../helpers/process-auto-px';
1+
import { processAutoPx } from '../process-auto-px';
22
import { CssMargin, CssMarginProps, CssMarginSmart } from '../../meta/style';
33
import { isObject } from '../../utils/is-object';
44
import { isUndefined } from '../../utils/is-undefined';

package/src/compiler/props/padding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { processAutoPx } from '../../helpers/process-auto-px';
1+
import { processAutoPx } from '../process-auto-px';
22
import { CssPadding, CssPaddingProps, CssPaddingSmart } from '../../meta/style';
33
import { isObject } from '../../utils/is-object';
44
import { isUndefined } from '../../utils/is-undefined';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { parseToHsl } from './parse-to-hsl';
2+
import { toColorString } from './to-color-string';
3+
4+
/**
5+
* Changes the hue of the color. Hue is a number between 0 to 360. The first
6+
* argument for adjustHue is the amount of degrees the color is rotated along
7+
* the color wheel.
8+
*
9+
* @example
10+
* background: adjustHue(180, '#448'),
11+
* background: adjustHue(180, 'rgba(101,100,205,0.7)'),
12+
*/
13+
export function adjustHue(degree: number, color: string): string {
14+
const hslColor = parseToHsl(color);
15+
return toColorString({
16+
...hslColor,
17+
hue: (hslColor.hue + degree) % 360,
18+
});
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { parseToHsl } from './parse-to-hsl';
2+
import { toColorString } from './to-color-string';
3+
4+
/**
5+
* Returns the complement of the provided color. This is identical to adjustHue(180, <color>).
6+
*
7+
* @example
8+
* background: complement('#448'),
9+
* background: complement('rgba(204,205,100,0.7)'),
10+
*/
11+
export function complement(color: string): string {
12+
const hslColor = parseToHsl(color);
13+
return toColorString({
14+
...hslColor,
15+
hue: (hslColor.hue + 180) % 360,
16+
});
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { guard } from '../../utils/guard';
2+
import { parseToHsl } from './parse-to-hsl';
3+
import { toColorString } from './to-color-string';
4+
5+
/**
6+
* Returns a string value for the darkened color.
7+
*
8+
* @example
9+
* background: darken(0.2, '#FFCD64')
10+
* background: darken(0.2, 'rgba(255,205,100,0.7)')
11+
*/
12+
export function darken(amount: number, color: string): string {
13+
const hslColor = parseToHsl(color);
14+
return toColorString({
15+
...hslColor,
16+
lightness: guard(0, 1, hslColor.lightness - amount),
17+
});
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { guard } from '../../utils/guard';
2+
import { parseToHsl } from './parse-to-hsl';
3+
import { toColorString } from './to-color-string';
4+
5+
/**
6+
* Decreases the intensity of a color. Its range is between 0 to 1. The first
7+
* argument of the desaturate function is the amount by how much the color
8+
* intensity should be decreased.
9+
*
10+
* @example
11+
* background: desaturate(0.2, '#CCCD64'),
12+
* background: desaturate(0.2, 'rgba(204,205,100,0.7)'),
13+
*/
14+
export function desaturate(amount: number, color: string): string {
15+
const hslColor = parseToHsl(color);
16+
return toColorString({
17+
...hslColor,
18+
saturation: guard(0, 1, hslColor.saturation - amount),
19+
});
20+
}

0 commit comments

Comments
 (0)