@udixio/theme 1.0.0-beta.9 → 1.0.0
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/.eslintrc.mjs +22 -0
- package/CHANGELOG.md +174 -0
- package/README.md +6 -68
- package/dist/API.d.ts +14 -0
- package/dist/API.d.ts.map +1 -0
- package/dist/LICENSE +202 -0
- package/dist/adapter/adapter.abstract.d.ts +10 -0
- package/dist/adapter/adapter.abstract.d.ts.map +1 -0
- package/dist/{config → adapter}/config.interface.d.ts +6 -5
- package/dist/adapter/config.interface.d.ts.map +1 -0
- package/dist/adapter/define-config.d.ts +3 -0
- package/dist/adapter/define-config.d.ts.map +1 -0
- package/dist/adapter/file-adapter.mixin.d.ts +18 -0
- package/dist/adapter/file-adapter.mixin.d.ts.map +1 -0
- package/dist/adapter/index.d.ts +4 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/adapters/index.d.ts +3 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/node.adapter.d.ts +7 -0
- package/dist/adapters/node.adapter.d.ts.map +1 -0
- package/dist/adapters/vite.adapter.d.ts +3 -0
- package/dist/adapters/vite.adapter.d.ts.map +1 -0
- package/dist/app.container.d.ts +5 -5
- package/dist/app.container.d.ts.map +1 -0
- package/dist/app.module.d.ts +1 -0
- package/dist/app.module.d.ts.map +1 -0
- package/dist/bootstrap.d.ts +3 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/color/color.api.d.ts +39 -0
- package/dist/color/color.api.d.ts.map +1 -0
- package/dist/color/color.manager.d.ts +24 -0
- package/dist/color/color.manager.d.ts.map +1 -0
- package/dist/color/color.module.d.ts +1 -0
- package/dist/color/color.module.d.ts.map +1 -0
- package/dist/color/color.utils.d.ts +8 -0
- package/dist/color/color.utils.d.ts.map +1 -0
- package/dist/color/configurable-color.d.ts +31 -0
- package/dist/color/configurable-color.d.ts.map +1 -0
- package/dist/color/default-color.d.ts +3 -0
- package/dist/color/default-color.d.ts.map +1 -0
- package/dist/color/index.d.ts +5 -4
- package/dist/color/index.d.ts.map +1 -0
- package/dist/index.cjs +3215 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3175 -7
- package/dist/material-color-utilities/contrastCurve.d.ts +1 -0
- package/dist/material-color-utilities/contrastCurve.d.ts.map +1 -0
- package/dist/material-color-utilities/dynamic_color.d.ts +89 -76
- package/dist/material-color-utilities/dynamic_color.d.ts.map +1 -0
- package/dist/material-color-utilities/hct_solver.d.ts +131 -0
- package/dist/material-color-utilities/hct_solver.d.ts.map +1 -0
- package/dist/material-color-utilities/htc.d.ts +77 -0
- package/dist/material-color-utilities/htc.d.ts.map +1 -0
- package/dist/material-color-utilities/index.d.ts +1 -0
- package/dist/material-color-utilities/index.d.ts.map +1 -0
- package/dist/material-color-utilities/toneDeltaPair.d.ts +19 -25
- package/dist/material-color-utilities/toneDeltaPair.d.ts.map +1 -0
- package/dist/plugin/index.d.ts +4 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/plugin.abstract.d.ts +19 -5
- package/dist/plugin/plugin.abstract.d.ts.map +1 -0
- package/dist/plugin/plugin.api.d.ts +10 -0
- package/dist/plugin/plugin.api.d.ts.map +1 -0
- package/dist/plugin/plugin.module.d.ts +1 -0
- package/dist/plugin/plugin.module.d.ts.map +1 -0
- package/dist/plugins/font/font.plugin.d.ts +50 -0
- package/dist/plugins/font/font.plugin.d.ts.map +1 -0
- package/dist/plugins/font/index.d.ts +2 -0
- package/dist/plugins/font/index.d.ts.map +1 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/theme/index.d.ts +7 -3
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/scheme.d.ts +20 -0
- package/dist/theme/scheme.d.ts.map +1 -0
- package/dist/theme/scheme.manager.d.ts +31 -0
- package/dist/theme/scheme.manager.d.ts.map +1 -0
- package/dist/theme/theme.api.d.ts +23 -0
- package/dist/theme/theme.api.d.ts.map +1 -0
- package/dist/theme/theme.module.d.ts +1 -0
- package/dist/theme/theme.module.d.ts.map +1 -0
- package/dist/theme/variant.d.ts +36 -0
- package/dist/theme/variant.d.ts.map +1 -0
- package/dist/theme/variant.manager.d.ts +14 -0
- package/dist/theme/variant.manager.d.ts.map +1 -0
- package/dist/theme/variants/expressive.variant.d.ts +3 -0
- package/dist/theme/variants/expressive.variant.d.ts.map +1 -0
- package/dist/theme/variants/index.d.ts +11 -0
- package/dist/theme/variants/index.d.ts.map +1 -0
- package/dist/theme/variants/neutral.variant.d.ts +3 -0
- package/dist/theme/variants/neutral.variant.d.ts.map +1 -0
- package/dist/theme/variants/tonal-spot.variant.d.ts +3 -0
- package/dist/theme/variants/tonal-spot.variant.d.ts.map +1 -0
- package/dist/theme/variants/vibrant.variant.d.ts +3 -0
- package/dist/theme/variants/vibrant.variant.d.ts.map +1 -0
- package/package.json +24 -87
- package/src/API.ts +23 -0
- package/src/adapter/adapter.abstract.ts +64 -0
- package/src/{config → adapter}/config.interface.ts +5 -5
- package/src/adapter/define-config.ts +11 -0
- package/src/adapter/file-adapter.mixin.ts +72 -0
- package/src/adapter/index.ts +3 -0
- package/src/adapters/index.ts +2 -0
- package/src/adapters/node.adapter.ts +49 -0
- package/src/adapters/vite.adapter.ts +79 -0
- package/src/app.container.ts +12 -36
- package/src/app.module.ts +2 -2
- package/src/bootstrap.ts +6 -0
- package/src/color/color.api.ts +75 -0
- package/src/color/color.manager.ts +213 -0
- package/src/color/color.module.ts +4 -4
- package/src/color/color.utils.ts +126 -0
- package/src/color/configurable-color.ts +67 -0
- package/src/color/default-color.ts +832 -0
- package/src/color/index.ts +4 -4
- package/src/index.test.ts +5 -0
- package/src/index.ts +6 -4
- package/src/material-color-utilities/dynamic_color.ts +286 -222
- package/src/material-color-utilities/hct_solver.ts +536 -0
- package/src/material-color-utilities/htc.ts +198 -0
- package/src/material-color-utilities/toneDeltaPair.ts +29 -11
- package/src/plugin/index.ts +3 -0
- package/src/plugin/plugin.abstract.ts +45 -5
- package/src/plugin/plugin.api.ts +51 -0
- package/src/plugin/plugin.module.ts +2 -2
- package/src/plugins/font/font.plugin.ts +203 -0
- package/src/plugins/font/index.ts +1 -0
- package/src/plugins/index.ts +1 -0
- package/src/theme/index.ts +6 -3
- package/src/theme/{services/scheme.service.ts → scheme.manager.ts} +39 -19
- package/src/theme/{entities/scheme.entity.ts → scheme.ts} +20 -4
- package/src/theme/{services/theme.service.ts → theme.api.ts} +23 -19
- package/src/theme/theme.module.ts +6 -4
- package/src/theme/variant.manager.ts +58 -0
- package/src/theme/variant.ts +53 -0
- package/src/theme/variants/expressive.variant.ts +81 -0
- package/src/theme/variants/index.ts +16 -0
- package/src/theme/variants/neutral.variant.ts +45 -0
- package/src/theme/variants/tonal-spot.variant.ts +35 -0
- package/src/theme/variants/vibrant.variant.ts +72 -0
- package/tsconfig.json +13 -0
- package/tsconfig.lib.json +33 -0
- package/tsconfig.spec.json +36 -0
- package/vite.config.ts +54 -0
- package/LICENSE +0 -21
- package/dist/app.service.d.ts +0 -13
- package/dist/color/color.interface.d.ts +0 -8
- package/dist/color/entities/color.entity.d.ts +0 -42
- package/dist/color/entities/index.d.ts +0 -1
- package/dist/color/models/default-color.model.d.ts +0 -3
- package/dist/color/models/index.d.ts +0 -1
- package/dist/color/services/color-manager.service.d.ts +0 -18
- package/dist/color/services/color.service.d.ts +0 -21
- package/dist/color/services/index.d.ts +0 -2
- package/dist/config/config.module.d.ts +0 -2
- package/dist/config/config.service.d.ts +0 -12
- package/dist/config/index.d.ts +0 -2
- package/dist/main.d.ts +0 -3
- package/dist/plugin/plugin.service.d.ts +0 -10
- package/dist/plugins/tailwind/Tailwind.plugin.d.ts +0 -14
- package/dist/plugins/tailwind/main.d.ts +0 -10
- package/dist/plugins/tailwind/plugins-tailwind/state.d.ts +0 -4
- package/dist/plugins/tailwind/plugins-tailwind/themer.d.ts +0 -4
- package/dist/theme/entities/index.d.ts +0 -2
- package/dist/theme/entities/scheme.entity.d.ts +0 -15
- package/dist/theme/entities/variant.entity.d.ts +0 -7
- package/dist/theme/models/index.d.ts +0 -1
- package/dist/theme/models/variant.model.d.ts +0 -8
- package/dist/theme/services/index.d.ts +0 -3
- package/dist/theme/services/scheme.service.d.ts +0 -17
- package/dist/theme/services/theme.service.d.ts +0 -22
- package/dist/theme/services/variant.service.d.ts +0 -13
- package/dist/theme.cjs.development.js +0 -1983
- package/dist/theme.cjs.development.js.map +0 -1
- package/dist/theme.cjs.production.min.js +0 -2
- package/dist/theme.cjs.production.min.js.map +0 -1
- package/dist/theme.esm.js +0 -1955
- package/dist/theme.esm.js.map +0 -1
- package/src/app.service.spec.ts +0 -15
- package/src/app.service.ts +0 -23
- package/src/color/color.interface.ts +0 -13
- package/src/color/entities/color.entity.ts +0 -71
- package/src/color/entities/index.ts +0 -1
- package/src/color/models/default-color.model.ts +0 -300
- package/src/color/models/index.ts +0 -1
- package/src/color/services/color-manager.service.ts +0 -191
- package/src/color/services/color.service.spec.ts +0 -28
- package/src/color/services/color.service.ts +0 -75
- package/src/color/services/index.ts +0 -2
- package/src/config/config.module.ts +0 -7
- package/src/config/config.service.ts +0 -74
- package/src/config/index.ts +0 -2
- package/src/main.ts +0 -14
- package/src/plugin/plugin.service.ts +0 -30
- package/src/plugins/tailwind/Tailwind.plugin.ts +0 -53
- package/src/plugins/tailwind/main.ts +0 -18
- package/src/plugins/tailwind/plugins-tailwind/state.ts +0 -88
- package/src/plugins/tailwind/plugins-tailwind/themer.ts +0 -53
- package/src/theme/entities/index.ts +0 -2
- package/src/theme/entities/variant.entity.ts +0 -39
- package/src/theme/models/index.ts +0 -1
- package/src/theme/models/variant.model.ts +0 -63
- package/src/theme/services/index.ts +0 -3
- package/src/theme/services/variant.service.ts +0 -52
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import { DislikeAnalyzer, Hct } from '@material/material-color-utilities';
|
|
2
|
-
import { ContrastCurve, ToneDeltaPair } from '../../material-color-utilities';
|
|
3
|
-
import { DynamicColor } from '../../material-color-utilities/dynamic_color';
|
|
4
|
-
import { highestSurface } from '../services/color-manager.service';
|
|
5
|
-
import { AddColorsOptions, ColorService } from '../services/color.service';
|
|
6
|
-
|
|
7
|
-
export type DynamicColorKey =
|
|
8
|
-
| 'background'
|
|
9
|
-
| 'onBackground'
|
|
10
|
-
| 'surface'
|
|
11
|
-
| 'surfaceDim'
|
|
12
|
-
| 'surfaceBright'
|
|
13
|
-
| 'surfaceContainerLowest'
|
|
14
|
-
| 'surfaceContainerLow'
|
|
15
|
-
| 'surfaceContainer'
|
|
16
|
-
| 'surfaceContainerHigh'
|
|
17
|
-
| 'surfaceContainerHighest'
|
|
18
|
-
| 'onSurface'
|
|
19
|
-
| 'surfaceVariant'
|
|
20
|
-
| 'onSurfaceVariant'
|
|
21
|
-
| 'inverseSurface'
|
|
22
|
-
| 'inverseOnSurface'
|
|
23
|
-
| 'outline'
|
|
24
|
-
| 'outlineVariant'
|
|
25
|
-
| 'shadow'
|
|
26
|
-
| 'scrim'
|
|
27
|
-
| 'surfaceTint'
|
|
28
|
-
| 'primary'
|
|
29
|
-
| 'onPrimary'
|
|
30
|
-
| 'primaryContainer'
|
|
31
|
-
| 'onPrimaryContainer'
|
|
32
|
-
| 'inversePrimary'
|
|
33
|
-
| 'secondary'
|
|
34
|
-
| 'onSecondary'
|
|
35
|
-
| 'secondaryContainer'
|
|
36
|
-
| 'onSecondaryContainer'
|
|
37
|
-
| 'tertiary'
|
|
38
|
-
| 'onTertiary'
|
|
39
|
-
| 'tertiaryContainer'
|
|
40
|
-
| 'onTertiaryContainer'
|
|
41
|
-
| 'error'
|
|
42
|
-
| 'onError'
|
|
43
|
-
| 'errorContainer'
|
|
44
|
-
| 'onErrorContainer'
|
|
45
|
-
| 'primaryFixed'
|
|
46
|
-
| 'primaryFixedDim'
|
|
47
|
-
| 'onPrimaryFixed'
|
|
48
|
-
| 'onPrimaryFixedVariant'
|
|
49
|
-
| 'secondaryFixed'
|
|
50
|
-
| 'secondaryFixedDim'
|
|
51
|
-
| 'onSecondaryFixed'
|
|
52
|
-
| 'onSecondaryFixedVariant'
|
|
53
|
-
| 'tertiaryFixed'
|
|
54
|
-
| 'tertiaryFixedDim'
|
|
55
|
-
| 'onTertiaryFixed'
|
|
56
|
-
| 'onTertiaryFixedVariant';
|
|
57
|
-
|
|
58
|
-
function findDesiredChromaByTone(
|
|
59
|
-
hue: number,
|
|
60
|
-
chroma: number,
|
|
61
|
-
tone: number,
|
|
62
|
-
byDecreasingTone: boolean
|
|
63
|
-
): number {
|
|
64
|
-
let answer = tone;
|
|
65
|
-
|
|
66
|
-
let closestToChroma = Hct.from(hue, chroma, tone);
|
|
67
|
-
if (closestToChroma.chroma < chroma) {
|
|
68
|
-
let chromaPeak = closestToChroma.chroma;
|
|
69
|
-
while (closestToChroma.chroma < chroma) {
|
|
70
|
-
answer += byDecreasingTone ? -1.0 : 1.0;
|
|
71
|
-
const potentialSolution = Hct.from(hue, chroma, answer);
|
|
72
|
-
if (chromaPeak > potentialSolution.chroma) {
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
if (Math.abs(potentialSolution.chroma - chroma) < 0.4) {
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const potentialDelta = Math.abs(potentialSolution.chroma - chroma);
|
|
80
|
-
const currentDelta = Math.abs(closestToChroma.chroma - chroma);
|
|
81
|
-
if (potentialDelta < currentDelta) {
|
|
82
|
-
closestToChroma = potentialSolution;
|
|
83
|
-
}
|
|
84
|
-
chromaPeak = Math.max(chromaPeak, potentialSolution.chroma);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return answer;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export const defaultColors: AddColorsOptions = (
|
|
92
|
-
colorService: ColorService
|
|
93
|
-
) => ({
|
|
94
|
-
fromPalettes: ['primary', 'secondary', 'tertiary'],
|
|
95
|
-
colors: {
|
|
96
|
-
background: {
|
|
97
|
-
palette: (s) => s.getPalette('neutral'),
|
|
98
|
-
tone: (s) => (s.isDark ? 6 : 98),
|
|
99
|
-
isBackground: true,
|
|
100
|
-
},
|
|
101
|
-
onBackground: {
|
|
102
|
-
palette: (s) => s.getPalette('neutral'),
|
|
103
|
-
tone: (s) => (s.isDark ? 90 : 10),
|
|
104
|
-
background: (s) => colorService.getColor('background').getDynamicColor(),
|
|
105
|
-
contrastCurve: new ContrastCurve(3, 3, 4.5, 7),
|
|
106
|
-
},
|
|
107
|
-
surface: {
|
|
108
|
-
palette: (s) => s.getPalette('neutral'),
|
|
109
|
-
tone: (s) => (s.isDark ? 6 : 98),
|
|
110
|
-
isBackground: true,
|
|
111
|
-
},
|
|
112
|
-
surfaceDim: {
|
|
113
|
-
palette: (s) => s.getPalette('neutral'),
|
|
114
|
-
tone: (s) => (s.isDark ? 6 : 87),
|
|
115
|
-
isBackground: true,
|
|
116
|
-
},
|
|
117
|
-
surfaceBright: {
|
|
118
|
-
palette: (s) => s.getPalette('neutral'),
|
|
119
|
-
tone: (s) => (s.isDark ? 24 : 98),
|
|
120
|
-
isBackground: true,
|
|
121
|
-
},
|
|
122
|
-
surfaceContainerLowest: {
|
|
123
|
-
palette: (s) => s.getPalette('neutral'),
|
|
124
|
-
tone: (s) => (s.isDark ? 4 : 100),
|
|
125
|
-
isBackground: true,
|
|
126
|
-
},
|
|
127
|
-
surfaceContainerLow: {
|
|
128
|
-
palette: (s) => s.getPalette('neutral'),
|
|
129
|
-
tone: (s) => (s.isDark ? 10 : 96),
|
|
130
|
-
isBackground: true,
|
|
131
|
-
},
|
|
132
|
-
surfaceContainer: {
|
|
133
|
-
palette: (s) => s.getPalette('neutral'),
|
|
134
|
-
tone: (s) => (s.isDark ? 12 : 94),
|
|
135
|
-
isBackground: true,
|
|
136
|
-
},
|
|
137
|
-
surfaceContainerHigh: {
|
|
138
|
-
palette: (s) => s.getPalette('neutral'),
|
|
139
|
-
tone: (s) => (s.isDark ? 17 : 92),
|
|
140
|
-
isBackground: true,
|
|
141
|
-
},
|
|
142
|
-
surfaceContainerHighest: {
|
|
143
|
-
palette: (s) => s.getPalette('neutral'),
|
|
144
|
-
tone: (s) => (s.isDark ? 22 : 90),
|
|
145
|
-
isBackground: true,
|
|
146
|
-
},
|
|
147
|
-
onSurface: {
|
|
148
|
-
palette: (s) => s.getPalette('neutral'),
|
|
149
|
-
tone: (s) => (s.isDark ? 90 : 10),
|
|
150
|
-
background: (s) => highestSurface(s, colorService),
|
|
151
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
|
|
152
|
-
},
|
|
153
|
-
surfaceVariant: {
|
|
154
|
-
palette: (s) => s.getPalette('neutralVariant'),
|
|
155
|
-
tone: (s) => (s.isDark ? 30 : 90),
|
|
156
|
-
isBackground: true,
|
|
157
|
-
},
|
|
158
|
-
onSurfaceVariant: {
|
|
159
|
-
palette: (s) => s.getPalette('neutralVariant'),
|
|
160
|
-
tone: (s) => (s.isDark ? 80 : 30),
|
|
161
|
-
background: (s) => highestSurface(s, colorService),
|
|
162
|
-
contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
|
|
163
|
-
},
|
|
164
|
-
inverseSurface: {
|
|
165
|
-
palette: (s) => s.getPalette('neutral'),
|
|
166
|
-
tone: (s) => (s.isDark ? 90 : 20),
|
|
167
|
-
},
|
|
168
|
-
inverseOnSurface: {
|
|
169
|
-
palette: (s) => s.getPalette('neutral'),
|
|
170
|
-
tone: (s) => (s.isDark ? 20 : 95),
|
|
171
|
-
background: (s) =>
|
|
172
|
-
colorService.getColor('inverseSurface').getDynamicColor(),
|
|
173
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
|
|
174
|
-
},
|
|
175
|
-
outline: {
|
|
176
|
-
palette: (s) => s.getPalette('neutralVariant'),
|
|
177
|
-
tone: (s) => (s.isDark ? 60 : 50),
|
|
178
|
-
background: (s) => highestSurface(s, colorService),
|
|
179
|
-
contrastCurve: new ContrastCurve(1.5, 3, 4.5, 7),
|
|
180
|
-
},
|
|
181
|
-
outlineVariant: {
|
|
182
|
-
palette: (s) => s.getPalette('neutralVariant'),
|
|
183
|
-
tone: (s) => (s.isDark ? 30 : 80),
|
|
184
|
-
background: (s) => highestSurface(s, colorService),
|
|
185
|
-
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
186
|
-
},
|
|
187
|
-
shadow: {
|
|
188
|
-
palette: (s) => s.getPalette('neutral'),
|
|
189
|
-
tone: (s) => 0,
|
|
190
|
-
},
|
|
191
|
-
scrim: {
|
|
192
|
-
palette: (s) => s.getPalette('neutral'),
|
|
193
|
-
tone: (s) => 0,
|
|
194
|
-
},
|
|
195
|
-
surfaceTint: {
|
|
196
|
-
palette: (s) => s.getPalette('neutral'),
|
|
197
|
-
tone: (s) => (s.isDark ? 80 : 40),
|
|
198
|
-
isBackground: true,
|
|
199
|
-
},
|
|
200
|
-
secondaryContainer: {
|
|
201
|
-
tone: (s) => {
|
|
202
|
-
const initialTone = s.isDark ? 30 : 90;
|
|
203
|
-
return findDesiredChromaByTone(
|
|
204
|
-
s.getPalette('secondary').hue,
|
|
205
|
-
s.getPalette('secondary').chroma,
|
|
206
|
-
initialTone,
|
|
207
|
-
!s.isDark
|
|
208
|
-
);
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
onSecondaryContainer: {
|
|
212
|
-
tone: (s) => {
|
|
213
|
-
return DynamicColor.foregroundTone(
|
|
214
|
-
colorService.getColor('secondaryContainer').getDynamicColor().tone(s),
|
|
215
|
-
4.5
|
|
216
|
-
);
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
tertiaryContainer: {
|
|
220
|
-
palette: (s) => s.getPalette('tertiary'),
|
|
221
|
-
tone: (s) => {
|
|
222
|
-
const proposedHct = s
|
|
223
|
-
.getPalette('tertiary')
|
|
224
|
-
.getHct(s.sourceColorHct.tone);
|
|
225
|
-
return DislikeAnalyzer.fixIfDisliked(proposedHct).tone;
|
|
226
|
-
},
|
|
227
|
-
},
|
|
228
|
-
onTertiaryContainer: {
|
|
229
|
-
palette: (s) => s.getPalette('tertiary'),
|
|
230
|
-
tone: (s) => {
|
|
231
|
-
return DynamicColor.foregroundTone(
|
|
232
|
-
colorService.getColor('tertiaryContainer').getDynamicColor().tone(s),
|
|
233
|
-
4.5
|
|
234
|
-
);
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
error: {
|
|
238
|
-
palette: (s) => s.getPalette('error'),
|
|
239
|
-
tone: (s) => (s.isDark ? 80 : 40),
|
|
240
|
-
isBackground: true,
|
|
241
|
-
background: (s) => highestSurface(s, colorService),
|
|
242
|
-
contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
|
|
243
|
-
toneDeltaPair: (s) =>
|
|
244
|
-
new ToneDeltaPair(
|
|
245
|
-
colorService.getColor('errorContainer').getDynamicColor(),
|
|
246
|
-
colorService.getColor('error').getDynamicColor(),
|
|
247
|
-
15,
|
|
248
|
-
'nearer',
|
|
249
|
-
false
|
|
250
|
-
),
|
|
251
|
-
},
|
|
252
|
-
onError: {
|
|
253
|
-
palette: (s) => s.getPalette('error'),
|
|
254
|
-
tone: (s) => (s.isDark ? 20 : 100),
|
|
255
|
-
background: (s) => colorService.getColor('error').getDynamicColor(),
|
|
256
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
|
|
257
|
-
},
|
|
258
|
-
errorContainer: {
|
|
259
|
-
palette: (s) => s.getPalette('error'),
|
|
260
|
-
tone: (s) => (s.isDark ? 30 : 90),
|
|
261
|
-
isBackground: true,
|
|
262
|
-
background: (s) => highestSurface(s, colorService),
|
|
263
|
-
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
264
|
-
toneDeltaPair: (s) =>
|
|
265
|
-
new ToneDeltaPair(
|
|
266
|
-
colorService.getColor('errorContainer').getDynamicColor(),
|
|
267
|
-
colorService.getColor('error').getDynamicColor(),
|
|
268
|
-
15,
|
|
269
|
-
'nearer',
|
|
270
|
-
false
|
|
271
|
-
),
|
|
272
|
-
},
|
|
273
|
-
onErrorContainer: {
|
|
274
|
-
palette: (s) => s.getPalette('error'),
|
|
275
|
-
tone: (s) => (s.isDark ? 90 : 10),
|
|
276
|
-
background: (s) =>
|
|
277
|
-
colorService.getColor('errorContainer').getDynamicColor(),
|
|
278
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
|
|
279
|
-
},
|
|
280
|
-
|
|
281
|
-
onTertiaryFixed: {
|
|
282
|
-
palette: (s) => s.getPalette('tertiary'),
|
|
283
|
-
tone: (s) => 10.0,
|
|
284
|
-
background: (s) =>
|
|
285
|
-
colorService.getColor('tertiaryFixedDim').getDynamicColor(),
|
|
286
|
-
secondBackground: (s) =>
|
|
287
|
-
colorService.getColor('tertiaryFixed').getDynamicColor(),
|
|
288
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
|
|
289
|
-
},
|
|
290
|
-
onTertiaryFixedVariant: {
|
|
291
|
-
palette: (s) => s.getPalette('tertiary'),
|
|
292
|
-
tone: (s) => 30.0,
|
|
293
|
-
background: (s) =>
|
|
294
|
-
colorService.getColor('tertiaryFixedDim').getDynamicColor(),
|
|
295
|
-
secondBackground: (s) =>
|
|
296
|
-
colorService.getColor('tertiaryFixed').getDynamicColor(),
|
|
297
|
-
contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
|
|
298
|
-
},
|
|
299
|
-
},
|
|
300
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './default-color.model';
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { ContrastCurve, ToneDeltaPair } from '../../material-color-utilities';
|
|
2
|
-
import { DynamicColor } from '../../material-color-utilities/dynamic_color';
|
|
3
|
-
import { SchemeEntity } from '../../theme/entities/scheme.entity';
|
|
4
|
-
|
|
5
|
-
import { ColorEntity, ColorOptions } from '../entities/color.entity';
|
|
6
|
-
import { SchemeService } from '../../theme/services/scheme.service';
|
|
7
|
-
import { DynamicColorKey } from '../models/default-color.model';
|
|
8
|
-
import { ColorService } from './color.service';
|
|
9
|
-
|
|
10
|
-
function capitalizeFirstLetter(string: string) {
|
|
11
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const highestSurface = (
|
|
15
|
-
s: SchemeEntity,
|
|
16
|
-
colorService: ColorManagerService | ColorService
|
|
17
|
-
): DynamicColor => {
|
|
18
|
-
if (colorService instanceof ColorService) {
|
|
19
|
-
return s.isDark
|
|
20
|
-
? colorService.getColor('surfaceBright').getDynamicColor()
|
|
21
|
-
: colorService.getColor('surfaceDim').getDynamicColor();
|
|
22
|
-
} else {
|
|
23
|
-
return s.isDark
|
|
24
|
-
? colorService.get('surfaceBright').getDynamicColor()
|
|
25
|
-
: colorService.get('surfaceDim').getDynamicColor();
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export class ColorManagerService {
|
|
30
|
-
private colorMap = new Map<string, ColorEntity>();
|
|
31
|
-
private readonly schemeService: SchemeService;
|
|
32
|
-
constructor({ schemeService }: { schemeService: SchemeService }) {
|
|
33
|
-
this.schemeService = schemeService;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
createOrUpdate(key: string, args: Partial<ColorOptions>): ColorEntity {
|
|
37
|
-
let colorEntity = this.colorMap.get(key);
|
|
38
|
-
if (!colorEntity) {
|
|
39
|
-
const { palette, tone } = args;
|
|
40
|
-
if (palette && tone) {
|
|
41
|
-
colorEntity = new ColorEntity(
|
|
42
|
-
{ ...args, palette, tone, name: key },
|
|
43
|
-
this.schemeService,
|
|
44
|
-
this
|
|
45
|
-
);
|
|
46
|
-
this.colorMap.set(key, colorEntity);
|
|
47
|
-
} else {
|
|
48
|
-
throw new Error(`Palette ${key} does not exist`);
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
colorEntity.update({ ...args, name: key });
|
|
52
|
-
this.colorMap.set(key, colorEntity);
|
|
53
|
-
}
|
|
54
|
-
return colorEntity;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public remove(key: string) {
|
|
58
|
-
return this.colorMap.delete(key);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public get(key: string): ColorEntity {
|
|
62
|
-
const colorEntity = this.colorMap.get(key);
|
|
63
|
-
if (colorEntity) {
|
|
64
|
-
return colorEntity;
|
|
65
|
-
} else {
|
|
66
|
-
throw new Error(`Color ${key} does not exist`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public getAll(): ReadonlyMap<string, ColorEntity> {
|
|
71
|
-
return this.colorMap;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
addFromPalette(key: string): void {
|
|
75
|
-
const colorKey = key as DynamicColorKey;
|
|
76
|
-
const ColorKey = capitalizeFirstLetter(key);
|
|
77
|
-
const onColorKey = ('on' + ColorKey) as DynamicColorKey;
|
|
78
|
-
const colorKeyContainer = (colorKey + 'Container') as DynamicColorKey;
|
|
79
|
-
const onColorKeyContainer = ('on' +
|
|
80
|
-
ColorKey +
|
|
81
|
-
'Container') as DynamicColorKey;
|
|
82
|
-
const inverseColorKey = ('inverse' + ColorKey) as DynamicColorKey;
|
|
83
|
-
const colorKeyFixed = (colorKey + 'Fixed') as DynamicColorKey;
|
|
84
|
-
const colorKeyFixedDim = (colorKey + 'FixedDim') as DynamicColorKey;
|
|
85
|
-
const onColorKeyFixed = ('on' + ColorKey + 'Fixed') as DynamicColorKey;
|
|
86
|
-
const onColorKeyFixedVariant = ('on' +
|
|
87
|
-
ColorKey +
|
|
88
|
-
'FixedVariant') as DynamicColorKey;
|
|
89
|
-
|
|
90
|
-
this.createOrUpdate(colorKey, {
|
|
91
|
-
palette: (s) => s.getPalette(key),
|
|
92
|
-
tone: (s) => {
|
|
93
|
-
return s.isDark ? 80 : 40;
|
|
94
|
-
},
|
|
95
|
-
isBackground: true,
|
|
96
|
-
background: (s) => highestSurface(s, this),
|
|
97
|
-
contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
|
|
98
|
-
toneDeltaPair: (s) =>
|
|
99
|
-
new ToneDeltaPair(
|
|
100
|
-
this.get(colorKeyContainer).getDynamicColor(),
|
|
101
|
-
this.get(colorKey).getDynamicColor(),
|
|
102
|
-
15,
|
|
103
|
-
'nearer',
|
|
104
|
-
false
|
|
105
|
-
),
|
|
106
|
-
});
|
|
107
|
-
this.createOrUpdate(onColorKey, {
|
|
108
|
-
palette: (s) => s.getPalette(key),
|
|
109
|
-
tone: (s) => {
|
|
110
|
-
return s.isDark ? 20 : 100;
|
|
111
|
-
},
|
|
112
|
-
background: (s) => this.get(colorKey).getDynamicColor(),
|
|
113
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
|
|
114
|
-
});
|
|
115
|
-
this.createOrUpdate(colorKeyContainer, {
|
|
116
|
-
palette: (s) => s.getPalette(key),
|
|
117
|
-
tone: (s) => {
|
|
118
|
-
return s.isDark ? 30 : 90;
|
|
119
|
-
},
|
|
120
|
-
isBackground: true,
|
|
121
|
-
background: (s) => highestSurface(s, this),
|
|
122
|
-
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
123
|
-
toneDeltaPair: (s) =>
|
|
124
|
-
new ToneDeltaPair(
|
|
125
|
-
this.get(colorKeyContainer).getDynamicColor(),
|
|
126
|
-
this.get(colorKey).getDynamicColor(),
|
|
127
|
-
15,
|
|
128
|
-
'nearer',
|
|
129
|
-
false
|
|
130
|
-
),
|
|
131
|
-
});
|
|
132
|
-
this.createOrUpdate(onColorKeyContainer, {
|
|
133
|
-
palette: (s) => s.getPalette(key),
|
|
134
|
-
tone: (s) => {
|
|
135
|
-
return s.isDark ? 90 : 10;
|
|
136
|
-
},
|
|
137
|
-
background: (s) => this.get(colorKeyContainer).getDynamicColor(),
|
|
138
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
|
|
139
|
-
});
|
|
140
|
-
this.createOrUpdate(inverseColorKey, {
|
|
141
|
-
palette: (s) => s.getPalette(key),
|
|
142
|
-
tone: (s) => (s.isDark ? 40 : 80),
|
|
143
|
-
background: (s) => this.get('inverseSurface').getDynamicColor(),
|
|
144
|
-
contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
|
|
145
|
-
});
|
|
146
|
-
this.createOrUpdate(colorKeyFixed, {
|
|
147
|
-
palette: (s) => s.getPalette(key),
|
|
148
|
-
tone: (s) => 90.0,
|
|
149
|
-
isBackground: true,
|
|
150
|
-
background: (s) => highestSurface(s, this),
|
|
151
|
-
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
152
|
-
toneDeltaPair: (s) =>
|
|
153
|
-
new ToneDeltaPair(
|
|
154
|
-
this.get(colorKeyFixed).getDynamicColor(),
|
|
155
|
-
this.get(colorKeyFixedDim).getDynamicColor(),
|
|
156
|
-
10,
|
|
157
|
-
'lighter',
|
|
158
|
-
true
|
|
159
|
-
),
|
|
160
|
-
});
|
|
161
|
-
this.createOrUpdate(colorKeyFixedDim, {
|
|
162
|
-
palette: (s) => s.getPalette(key),
|
|
163
|
-
tone: (s) => 80.0,
|
|
164
|
-
isBackground: true,
|
|
165
|
-
background: (s) => highestSurface(s, this),
|
|
166
|
-
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
167
|
-
toneDeltaPair: (s) =>
|
|
168
|
-
new ToneDeltaPair(
|
|
169
|
-
this.get(colorKeyFixed).getDynamicColor(),
|
|
170
|
-
this.get(colorKeyFixedDim).getDynamicColor(),
|
|
171
|
-
10,
|
|
172
|
-
'lighter',
|
|
173
|
-
true
|
|
174
|
-
),
|
|
175
|
-
});
|
|
176
|
-
this.createOrUpdate(onColorKeyFixed, {
|
|
177
|
-
palette: (s) => s.getPalette(key),
|
|
178
|
-
tone: (s) => 10.0,
|
|
179
|
-
background: (s) => this.get(colorKeyFixedDim).getDynamicColor(),
|
|
180
|
-
secondBackground: (s) => this.get(colorKeyFixed).getDynamicColor(),
|
|
181
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21),
|
|
182
|
-
});
|
|
183
|
-
this.createOrUpdate(onColorKeyFixedVariant, {
|
|
184
|
-
palette: (s) => s.getPalette(key),
|
|
185
|
-
tone: (s) => 30.0,
|
|
186
|
-
background: (s) => this.get(colorKeyFixedDim).getDynamicColor(),
|
|
187
|
-
secondBackground: (s) => this.get(colorKeyFixed).getDynamicColor(),
|
|
188
|
-
contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { ColorService } from './color.service';
|
|
2
|
-
import { ColorModule } from '../color.module';
|
|
3
|
-
import { Test } from '@nestjs/testing';
|
|
4
|
-
|
|
5
|
-
describe('ColorService', () => {
|
|
6
|
-
let colorService: ColorService;
|
|
7
|
-
|
|
8
|
-
beforeEach(async () => {
|
|
9
|
-
const moduleRef = await Test.createTestingModule({
|
|
10
|
-
imports: [ColorModule],
|
|
11
|
-
}).compile();
|
|
12
|
-
|
|
13
|
-
colorService = moduleRef.get(ColorService);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should return an array of cats', async () => {
|
|
17
|
-
const result = colorService['dynamicColorService']['colorMap'].entries();
|
|
18
|
-
console.log(result);
|
|
19
|
-
|
|
20
|
-
colorService.addBaseColors();
|
|
21
|
-
// for (const [key, value] of Object.entries(defaultColorModel.colors)) {
|
|
22
|
-
// colorService.update(key, value);
|
|
23
|
-
// }
|
|
24
|
-
|
|
25
|
-
console.dir(result, { depth: null });
|
|
26
|
-
// expect(await catsController.findAll()).toBe(result);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { ColorManagerService } from './color-manager.service';
|
|
2
|
-
import { ColorInterface } from '../color.interface';
|
|
3
|
-
import { ColorEntity, ColorOptions } from '../entities';
|
|
4
|
-
|
|
5
|
-
type AddColors = {
|
|
6
|
-
colors?: Record<string, Partial<ColorOptions>>;
|
|
7
|
-
fromPalettes?: string[] | string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type AddColorsOptions =
|
|
11
|
-
| AddColors
|
|
12
|
-
| ((colorService: ColorService) => AddColors);
|
|
13
|
-
|
|
14
|
-
export class ColorService implements ColorInterface {
|
|
15
|
-
private readonly colorManagerService: ColorManagerService;
|
|
16
|
-
constructor({
|
|
17
|
-
colorManagerService,
|
|
18
|
-
}: {
|
|
19
|
-
colorManagerService: ColorManagerService;
|
|
20
|
-
}) {
|
|
21
|
-
this.colorManagerService = colorManagerService;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
getColors() {
|
|
25
|
-
return this.colorManagerService.getAll();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// getColors() {
|
|
29
|
-
// const colors: Record<string, string> = {};
|
|
30
|
-
//
|
|
31
|
-
// for (const [key, value] of this.colorManagerService.getAll()) {
|
|
32
|
-
// colors[key] = hexFromArgb(value.getArgb(this.schemeService.get()));
|
|
33
|
-
// }
|
|
34
|
-
//
|
|
35
|
-
// return colors;
|
|
36
|
-
// }
|
|
37
|
-
|
|
38
|
-
addColor(key: string, color: Partial<ColorOptions>): ColorEntity {
|
|
39
|
-
return this.colorManagerService.createOrUpdate(key, color);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
addColors(args: AddColorsOptions | AddColorsOptions[]) {
|
|
43
|
-
const colorsEntity: ColorEntity[] = [];
|
|
44
|
-
if (!Array.isArray(args)) args = [args];
|
|
45
|
-
args.forEach((args) => {
|
|
46
|
-
if (typeof args === 'function') {
|
|
47
|
-
args = args(this);
|
|
48
|
-
}
|
|
49
|
-
if (args.fromPalettes) {
|
|
50
|
-
if (!Array.isArray(args.fromPalettes))
|
|
51
|
-
args.fromPalettes = [args.fromPalettes];
|
|
52
|
-
args.fromPalettes.map((paletteKey) => {
|
|
53
|
-
this.colorManagerService.addFromPalette(paletteKey);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
if (args.colors) {
|
|
57
|
-
Object.keys(args.colors).map((key) =>
|
|
58
|
-
this.addColor(key, args.colors![key])
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
getColor(key: string): ColorEntity {
|
|
65
|
-
return this.colorManagerService.get(key);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
removeColor(key: string): boolean {
|
|
69
|
-
return this.colorManagerService.remove(key);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
updateColor(key: string, newColor: Partial<ColorOptions>): ColorEntity {
|
|
73
|
-
return this.colorManagerService.createOrUpdate(key, newColor);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { ConfigInterface } from './config.interface';
|
|
2
|
-
|
|
3
|
-
import { resolve } from 'path';
|
|
4
|
-
import { defaultColors } from '../color';
|
|
5
|
-
import { VariantModel } from '../theme';
|
|
6
|
-
import { AppService } from '../app.service';
|
|
7
|
-
|
|
8
|
-
export function defineConfig(configObject: ConfigInterface): ConfigInterface {
|
|
9
|
-
if (!configObject || typeof configObject !== 'object') {
|
|
10
|
-
throw new Error('The configuration is missing or not an object');
|
|
11
|
-
}
|
|
12
|
-
if (!('sourceColor' in configObject)) {
|
|
13
|
-
throw new Error('Invalid configuration');
|
|
14
|
-
}
|
|
15
|
-
return configObject as ConfigInterface;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class ConfigService {
|
|
19
|
-
configPath = './theme.config.ts';
|
|
20
|
-
|
|
21
|
-
private appService: AppService;
|
|
22
|
-
|
|
23
|
-
constructor({ appService }: { appService: AppService }) {
|
|
24
|
-
this.appService = appService;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public async loadConfig(): Promise<void> {
|
|
28
|
-
const { themeService, colorService, pluginService } = this.appService;
|
|
29
|
-
const {
|
|
30
|
-
sourceColor,
|
|
31
|
-
contrastLevel = 0,
|
|
32
|
-
isDark = false,
|
|
33
|
-
variant = VariantModel.tonalSpot,
|
|
34
|
-
palettes,
|
|
35
|
-
colors,
|
|
36
|
-
useDefaultColors = true,
|
|
37
|
-
plugins,
|
|
38
|
-
} = await this.getConfig();
|
|
39
|
-
themeService.create({
|
|
40
|
-
contrastLevel: contrastLevel,
|
|
41
|
-
isDark: isDark,
|
|
42
|
-
sourceColorHex: sourceColor,
|
|
43
|
-
variant: variant,
|
|
44
|
-
});
|
|
45
|
-
if (palettes) {
|
|
46
|
-
Object.entries(palettes).forEach(([key, value]) =>
|
|
47
|
-
themeService.addCustomPalette(key, value)
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
if (useDefaultColors) {
|
|
51
|
-
colorService.addColors(defaultColors);
|
|
52
|
-
}
|
|
53
|
-
if (colors) {
|
|
54
|
-
colorService.addColors(colors);
|
|
55
|
-
}
|
|
56
|
-
if (plugins) {
|
|
57
|
-
plugins.forEach((plugin) => {
|
|
58
|
-
if (Array.isArray(plugin)) {
|
|
59
|
-
pluginService.addPlugin(plugin[0], plugin[1]);
|
|
60
|
-
} else {
|
|
61
|
-
pluginService.addPlugin(plugin, {});
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
pluginService.loadPlugins(this.appService);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
private async getConfig(): Promise<ConfigInterface> {
|
|
69
|
-
const path = resolve(this.configPath);
|
|
70
|
-
const configImport = await import(path);
|
|
71
|
-
const config: unknown = configImport.default;
|
|
72
|
-
return config as ConfigInterface;
|
|
73
|
-
}
|
|
74
|
-
}
|
package/src/config/index.ts
DELETED