@udixio/theme 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +73 -0
- package/dist/app.module.d.ts +2 -0
- package/dist/app.service.d.ts +7 -0
- package/dist/color/color-manager.service.d.ts +15 -0
- package/dist/color/color.interface.d.ts +9 -0
- package/dist/color/color.module.d.ts +2 -0
- package/dist/color/color.service.d.ts +13 -0
- package/dist/color/entities/color.entity.d.ts +37 -0
- package/dist/color/models/default-color.model.d.ts +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -0
- package/dist/main.d.ts +2 -0
- package/dist/material-color-utilities/contrastCurve.d.ts +46 -0
- package/dist/material-color-utilities/dynamic_color.d.ts +171 -0
- package/dist/material-color-utilities/index.d.ts +2 -0
- package/dist/material-color-utilities/toneDeltaPair.d.ts +60 -0
- package/dist/theme/entities/scheme.entity.d.ts +15 -0
- package/dist/theme/entities/variant.entity.d.ts +6 -0
- package/dist/theme/models/variant.model.d.ts +8 -0
- package/dist/theme/services/scheme.service.d.ts +12 -0
- package/dist/theme/services/theme.service.d.ts +13 -0
- package/dist/theme/services/variant.service.d.ts +7 -0
- package/dist/theme/theme.module.d.ts +2 -0
- package/dist/theme.cjs.development.js +1310 -0
- package/dist/theme.cjs.development.js.map +1 -0
- package/dist/theme.cjs.production.min.js +2 -0
- package/dist/theme.cjs.production.min.js.map +1 -0
- package/dist/theme.esm.js +1306 -0
- package/dist/theme.esm.js.map +1 -0
- package/package.json +101 -0
- package/src/app.module.ts +10 -0
- package/src/app.service.spec.ts +15 -0
- package/src/app.service.ts +11 -0
- package/src/color/color-manager.service.ts +186 -0
- package/src/color/color.interface.ts +15 -0
- package/src/color/color.module.ts +11 -0
- package/src/color/color.service.spec.ts +28 -0
- package/src/color/color.service.ts +52 -0
- package/src/color/entities/color.entity.ts +60 -0
- package/src/color/models/default-color.model.ts +297 -0
- package/src/index.ts +1 -0
- package/src/main.ts +11 -0
- package/src/material-color-utilities/contrastCurve.ts +63 -0
- package/src/material-color-utilities/dynamic_color.ts +450 -0
- package/src/material-color-utilities/index.ts +2 -0
- package/src/material-color-utilities/toneDeltaPair.ts +64 -0
- package/src/theme/entities/scheme.entity.ts +44 -0
- package/src/theme/entities/variant.entity.ts +38 -0
- package/src/theme/models/variant.model.ts +56 -0
- package/src/theme/services/scheme.service.ts +52 -0
- package/src/theme/services/theme.service.ts +58 -0
- package/src/theme/services/variant.service.ts +17 -0
- package/src/theme/theme.module.ts +10 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { SchemeEntity, SchemeOptions } from '../entities/scheme.entity';
|
|
3
|
+
import {
|
|
4
|
+
argbFromHex,
|
|
5
|
+
Hct,
|
|
6
|
+
TonalPalette,
|
|
7
|
+
} from '@material/material-color-utilities';
|
|
8
|
+
import mergeDeep from 'merge-deep';
|
|
9
|
+
|
|
10
|
+
export type SchemeServiceOptions = Omit<
|
|
11
|
+
SchemeOptions,
|
|
12
|
+
'palettes' | 'sourceColorArgb'
|
|
13
|
+
> & {
|
|
14
|
+
sourceColorHex: string;
|
|
15
|
+
palettes: Record<string, (sourceColorHct: Hct) => TonalPalette>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
@Injectable()
|
|
19
|
+
export class SchemeService {
|
|
20
|
+
private schemeEntity?: SchemeEntity;
|
|
21
|
+
private options?: SchemeServiceOptions;
|
|
22
|
+
|
|
23
|
+
createOrUpdate(options: Partial<SchemeServiceOptions>) {
|
|
24
|
+
this.options = mergeDeep(this.options, options);
|
|
25
|
+
const palettes = new Map<string, TonalPalette>();
|
|
26
|
+
|
|
27
|
+
const sourceColorArgb = argbFromHex(this.options.sourceColorHex);
|
|
28
|
+
const sourceColorHct: Hct = Hct.fromInt(sourceColorArgb);
|
|
29
|
+
|
|
30
|
+
if (!this.options.palettes) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
for (const [key, paletteFunction] of Object.entries(
|
|
34
|
+
this.options.palettes
|
|
35
|
+
)) {
|
|
36
|
+
const palette: TonalPalette = paletteFunction(sourceColorHct);
|
|
37
|
+
palettes.set(key, palette);
|
|
38
|
+
}
|
|
39
|
+
this.schemeEntity = new SchemeEntity({
|
|
40
|
+
...this.options,
|
|
41
|
+
palettes: palettes,
|
|
42
|
+
sourceColorArgb: sourceColorArgb,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get(): SchemeEntity {
|
|
47
|
+
if (!this.schemeEntity) {
|
|
48
|
+
throw new Error('Scheme is not created');
|
|
49
|
+
}
|
|
50
|
+
return this.schemeEntity;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DynamicColor } from '@material/material-color-utilities';
|
|
2
|
+
import { Injectable } from '@nestjs/common';
|
|
3
|
+
import { SchemeService, SchemeServiceOptions } from './scheme.service';
|
|
4
|
+
import { VariantService } from './variant.service';
|
|
5
|
+
import { VariantEntity } from '../entities/variant.entity';
|
|
6
|
+
|
|
7
|
+
type ThemeOptions = Omit<SchemeServiceOptions, 'palettes'>;
|
|
8
|
+
|
|
9
|
+
const colorPaletteKeyColor = DynamicColor.fromPalette({
|
|
10
|
+
name: 'primary_palette_key_color',
|
|
11
|
+
palette: (s) => s.primaryPalette,
|
|
12
|
+
tone: (s) => s.primaryPalette.keyColor.tone,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
@Injectable()
|
|
16
|
+
export class ThemeService {
|
|
17
|
+
constructor(
|
|
18
|
+
private schemeService: SchemeService,
|
|
19
|
+
private variantService: VariantService
|
|
20
|
+
) {
|
|
21
|
+
// this.addPalette({key: "primary", addDefaultColors: true})
|
|
22
|
+
// this.addPalette({key: "secondary", addDefaultColors: true})
|
|
23
|
+
// this.addPalette({key: "tertiary", addDefaultColors: true})
|
|
24
|
+
// this.addPalette({key: "error", palette: TonalPalette.fromHueAndChroma(25.0, 84.0)})
|
|
25
|
+
// this.addPalette({key: "neutral"})
|
|
26
|
+
// this.addPalette({key: "neutralVariant"})
|
|
27
|
+
}
|
|
28
|
+
// addPalette({key, palette, addDefaultColors}: {key: string; palette: TonalPalette; addDefaultColors: boolean}) {
|
|
29
|
+
// this.themeOptions.palettes.set(key, palette);
|
|
30
|
+
// if (addDefaultColors){
|
|
31
|
+
// this.colorService.addPalette(key)
|
|
32
|
+
// }
|
|
33
|
+
// }
|
|
34
|
+
|
|
35
|
+
// create(args: ThemeOptions): SchemeService {
|
|
36
|
+
// return new SchemeService(args, this.colorService)
|
|
37
|
+
// }
|
|
38
|
+
//
|
|
39
|
+
// update(options: Partial<ThemeOptions>): SchemeService {
|
|
40
|
+
// Object.assign(this.themeOptions, options);
|
|
41
|
+
// return this.theme();
|
|
42
|
+
// }
|
|
43
|
+
|
|
44
|
+
create(options: ThemeOptions) {
|
|
45
|
+
this.schemeService.createOrUpdate(options);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
addVariant(variant: VariantEntity) {
|
|
49
|
+
this.variantService.set(variant);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
update(options: Partial<ThemeOptions>) {
|
|
53
|
+
this.schemeService.createOrUpdate(options);
|
|
54
|
+
}
|
|
55
|
+
// theme(): SchemeService {
|
|
56
|
+
// return new SchemeService(this.themeOptions, this.colorService)
|
|
57
|
+
// }
|
|
58
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SchemeService } from './scheme.service';
|
|
2
|
+
import { VariantEntity } from '../entities/variant.entity';
|
|
3
|
+
import { Injectable } from '@nestjs/common';
|
|
4
|
+
import { TonalPalette } from '@material/material-color-utilities';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class VariantService {
|
|
8
|
+
constructor(private schemeService: SchemeService) {}
|
|
9
|
+
|
|
10
|
+
set(variantEntity: VariantEntity) {
|
|
11
|
+
if (!variantEntity.palettes.error) {
|
|
12
|
+
variantEntity.palettes.error = () =>
|
|
13
|
+
TonalPalette.fromHueAndChroma(25.0, 84.0);
|
|
14
|
+
}
|
|
15
|
+
this.schemeService.createOrUpdate(variantEntity);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { SchemeService } from './services/scheme.service';
|
|
3
|
+
import { ThemeService } from './services/theme.service';
|
|
4
|
+
import { VariantService } from './services/variant.service';
|
|
5
|
+
|
|
6
|
+
@Module({
|
|
7
|
+
providers: [SchemeService, ThemeService, VariantService],
|
|
8
|
+
exports: [ThemeService, SchemeService],
|
|
9
|
+
})
|
|
10
|
+
export class ThemeModule {}
|