theme-vir 25.7.0 → 25.7.1
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type CssVarName } from 'lit-css-vars';
|
|
2
2
|
import { type RequireAtLeastOne } from 'type-fest';
|
|
3
|
-
import { type ColorInit, type ColorTheme, type ColorThemeInit } from './color-theme.js';
|
|
3
|
+
import { type ColorInit, type ColorTheme, type ColorThemeInit, type NoRefColorInit } from './color-theme.js';
|
|
4
4
|
/**
|
|
5
5
|
* Input for {@link defineColorThemeOverride} color overrides.
|
|
6
6
|
*
|
|
@@ -26,11 +26,11 @@ export type ColorThemeOverride<Init extends ColorThemeInit = ColorThemeInit> = {
|
|
|
26
26
|
*
|
|
27
27
|
* @category Color Theme
|
|
28
28
|
*/
|
|
29
|
-
export declare function defineColorThemeOverride<const Init extends ColorThemeInit>(originalTheme: ColorTheme<Init>, overrideName: string, { defaultOverride, colorOverrides, }: RequireAtLeastOne<{
|
|
29
|
+
export declare function defineColorThemeOverride<const Init extends ColorThemeInit>(originalTheme: ColorTheme<Init>, overrideName: string, { defaultOverride, colorOverrides, }: Readonly<RequireAtLeastOne<{
|
|
30
30
|
/** Override the default foreground and/or background colors. */
|
|
31
|
-
defaultOverride:
|
|
32
|
-
colorOverrides: ColorThemeOverrideInit<ColorTheme<Init
|
|
33
|
-
}
|
|
31
|
+
defaultOverride: Readonly<NoRefColorInit>;
|
|
32
|
+
colorOverrides: Readonly<ColorThemeOverrideInit<ColorTheme<Init>>>;
|
|
33
|
+
}>>): ColorThemeOverride<Init>;
|
|
34
34
|
/**
|
|
35
35
|
* Set all color theme CSS vars on the given element. If no override is given, the theme color
|
|
36
36
|
* default values are assigned.
|
|
@@ -6,7 +6,7 @@ function applyCssVarOverride({ originalTheme, layerKey, themeColor, override, ov
|
|
|
6
6
|
if (!layerOverride) {
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
|
-
overrideValues[String(themeColor[layerKey].name)] = String(createColorCssVarDefault(layerKey, layerOverride, originalTheme));
|
|
9
|
+
overrideValues[String(themeColor[layerKey].name)] = String(createColorCssVarDefault(layerKey, layerOverride, originalTheme.init.default, originalTheme.init.colors));
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Define a color theme override. Use this to define multiple theme variations, like light mode vs
|
|
@@ -51,10 +51,10 @@ export function defineColorThemeOverride(originalTheme, overrideName, { defaultO
|
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
const asTheme = defineColorTheme({
|
|
54
|
-
...originalTheme.
|
|
54
|
+
...originalTheme.init.default,
|
|
55
55
|
...defaultOverride,
|
|
56
56
|
}, {
|
|
57
|
-
...originalTheme.init,
|
|
57
|
+
...originalTheme.init.colors,
|
|
58
58
|
...colorOverrides,
|
|
59
59
|
});
|
|
60
60
|
return {
|
|
@@ -26,6 +26,15 @@ export type ColorInit = RequireAtLeastOne<{
|
|
|
26
26
|
foreground: ColorInitValue;
|
|
27
27
|
background: ColorInitValue;
|
|
28
28
|
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Same as {@link ColorInit} but without references.
|
|
31
|
+
*
|
|
32
|
+
* @category Internal
|
|
33
|
+
*/
|
|
34
|
+
export type NoRefColorInit = RequireAtLeastOne<{
|
|
35
|
+
foreground: Exclude<ColorInitValue, ColorInitReference>;
|
|
36
|
+
background: Exclude<ColorInitValue, ColorInitReference>;
|
|
37
|
+
}>;
|
|
29
38
|
/**
|
|
30
39
|
* A defined individual color from a color theme.
|
|
31
40
|
*
|
|
@@ -56,7 +65,10 @@ export type ColorTheme<Init extends ColorThemeInit = ColorThemeInit> = {
|
|
|
56
65
|
colors: AllColorThemeColors<Init>;
|
|
57
66
|
inverse: AllColorThemeColors<Init>;
|
|
58
67
|
/** The original init object for this theme. */
|
|
59
|
-
init:
|
|
68
|
+
init: {
|
|
69
|
+
colors: Init;
|
|
70
|
+
default: RequiredAndNotNull<NoRefColorInit>;
|
|
71
|
+
};
|
|
60
72
|
};
|
|
61
73
|
/**
|
|
62
74
|
* All colors within a {@link ColorTheme}.
|
|
@@ -66,14 +78,14 @@ export type ColorTheme<Init extends ColorThemeInit = ColorThemeInit> = {
|
|
|
66
78
|
export type AllColorThemeColors<Init extends ColorThemeInit = ColorThemeInit> = {
|
|
67
79
|
[ColorName in keyof Init as ColorName extends CssVarName ? ColorName : never]: ColorName extends CssVarName ? Init[ColorName] extends ColorInit ? ColorThemeColor<Init[ColorName], ColorName> : never : never;
|
|
68
80
|
} & {
|
|
69
|
-
[themeDefaultKey]: ColorThemeColor<RequiredAndNotNull<
|
|
81
|
+
[themeDefaultKey]: ColorThemeColor<RequiredAndNotNull<NoRefColorInit>, typeof themeDefaultKey>;
|
|
70
82
|
};
|
|
71
83
|
/**
|
|
72
84
|
* Handles a color init value.
|
|
73
85
|
*
|
|
74
86
|
* @category Internal
|
|
75
87
|
*/
|
|
76
|
-
export declare function createColorCssVarDefault(fromName: string, init: ColorInitValue,
|
|
88
|
+
export declare function createColorCssVarDefault(fromName: string, init: ColorInitValue, defaultInit: RequiredAndNotNull<NoRefColorInit>, colorsInit: ColorThemeInit): Exclude<ColorInitValue, ColorInitReference>;
|
|
77
89
|
/**
|
|
78
90
|
* Default foreground/background color theme used in {@link ColorTheme}. Do not define a theme color
|
|
79
91
|
* with this name!
|
|
@@ -86,4 +98,4 @@ export declare const themeDefaultKey = "theme-default";
|
|
|
86
98
|
*
|
|
87
99
|
* @category Color Theme
|
|
88
100
|
*/
|
|
89
|
-
export declare function defineColorTheme<const Init extends ColorThemeInit>(defaultInit: RequiredAndNotNull<
|
|
101
|
+
export declare function defineColorTheme<const Init extends ColorThemeInit>(defaultInit: RequiredAndNotNull<NoRefColorInit>, allColorsInit: Init): ColorTheme<Init>;
|
|
@@ -6,18 +6,24 @@ import { defineCssVars, } from 'lit-css-vars';
|
|
|
6
6
|
*
|
|
7
7
|
* @category Internal
|
|
8
8
|
*/
|
|
9
|
-
export function createColorCssVarDefault(fromName, init,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
export function createColorCssVarDefault(fromName, init, defaultInit, colorsInit) {
|
|
10
|
+
const referenceKey = check.hasKey(init, 'refBackground')
|
|
11
|
+
? 'refBackground'
|
|
12
|
+
: check.hasKey(init, 'refForeground')
|
|
13
|
+
? 'refForeground'
|
|
14
|
+
: undefined;
|
|
15
|
+
const reference = referenceKey && check.hasKey(init, referenceKey) ? init[referenceKey] : undefined;
|
|
16
|
+
if (reference) {
|
|
17
|
+
const layerKey = referenceKey === 'refBackground' ? 'background' : 'foreground';
|
|
18
|
+
const referenced = colorsInit[reference];
|
|
19
|
+
if (!referenced) {
|
|
20
|
+
throw new Error(`Color theme ${referenceKey} reference '${reference}' does not exist. (Referenced from '${fromName}'.)`);
|
|
13
21
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return `var(--${init.refForeground}-fg)`;
|
|
22
|
+
const colorValue = referenced[layerKey] ||
|
|
23
|
+
(layerKey === 'foreground'
|
|
24
|
+
? createColorCssVarDefault('default-fg', defaultInit.foreground, defaultInit, colorsInit)
|
|
25
|
+
: createColorCssVarDefault('default-bg', defaultInit.background, defaultInit, colorsInit));
|
|
26
|
+
return `var(--${reference}-${layerKey === 'foreground' ? 'fg' : 'bg'}, ${createColorCssVarDefault(reference, colorValue, defaultInit, colorsInit)})`;
|
|
21
27
|
}
|
|
22
28
|
else {
|
|
23
29
|
return init;
|
|
@@ -40,10 +46,10 @@ export function defineColorTheme(defaultInit, allColorsInit) {
|
|
|
40
46
|
throw new Error(`Cannot define theme color by name '${themeDefaultKey}', it is used internally.`);
|
|
41
47
|
}
|
|
42
48
|
const defaultColors = defineCssVars({
|
|
43
|
-
'default-fg': createColorCssVarDefault('default-fg', defaultInit.foreground, allColorsInit),
|
|
44
|
-
'default-bg': createColorCssVarDefault('default-bg', defaultInit.background, allColorsInit),
|
|
45
|
-
'default-inverse-fg': createColorCssVarDefault('default-inverse-fg', defaultInit.background, allColorsInit),
|
|
46
|
-
'default-inverse-bg': createColorCssVarDefault('default-inverse-bg', defaultInit.foreground, allColorsInit),
|
|
49
|
+
'default-fg': createColorCssVarDefault('default-fg', defaultInit.foreground, defaultInit, allColorsInit),
|
|
50
|
+
'default-bg': createColorCssVarDefault('default-bg', defaultInit.background, defaultInit, allColorsInit),
|
|
51
|
+
'default-inverse-fg': createColorCssVarDefault('default-inverse-fg', defaultInit.background, defaultInit, allColorsInit),
|
|
52
|
+
'default-inverse-bg': createColorCssVarDefault('default-inverse-bg', defaultInit.foreground, defaultInit, allColorsInit),
|
|
47
53
|
});
|
|
48
54
|
const cssVarsSetup = getObjectTypedEntries(allColorsInit).reduce((accum, [colorName, colorInit,]) => {
|
|
49
55
|
const names = createCssVarNames(colorName);
|
|
@@ -51,13 +57,13 @@ export function defineColorTheme(defaultInit, allColorsInit) {
|
|
|
51
57
|
? createColorCssVarDefault([
|
|
52
58
|
colorName,
|
|
53
59
|
'foreground',
|
|
54
|
-
].join(' '), colorInit.foreground, allColorsInit)
|
|
60
|
+
].join(' '), colorInit.foreground, defaultInit, allColorsInit)
|
|
55
61
|
: `var(${defaultColors['default-fg'].name}, ${defaultColors['default-fg'].default})`;
|
|
56
62
|
accum[names.background] = colorInit.background
|
|
57
63
|
? createColorCssVarDefault([
|
|
58
64
|
colorName,
|
|
59
65
|
'background',
|
|
60
|
-
].join(' '), colorInit.background, allColorsInit)
|
|
66
|
+
].join(' '), colorInit.background, defaultInit, allColorsInit)
|
|
61
67
|
: `var(${defaultColors['default-bg'].name}, ${defaultColors['default-bg'].default})`;
|
|
62
68
|
accum[names.foregroundInverse] =
|
|
63
69
|
`var(--${names.background}, ${accum[names.background]})`;
|
|
@@ -117,7 +123,10 @@ export function defineColorTheme(defaultInit, allColorsInit) {
|
|
|
117
123
|
[themeDefaultKey]: themeDefaultInverseColors,
|
|
118
124
|
...inverseColors,
|
|
119
125
|
},
|
|
120
|
-
init:
|
|
126
|
+
init: {
|
|
127
|
+
colors: allColorsInit,
|
|
128
|
+
default: defaultInit,
|
|
129
|
+
},
|
|
121
130
|
};
|
|
122
131
|
}
|
|
123
132
|
function createCssVarNames(colorName) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "theme-vir",
|
|
3
|
-
"version": "25.7.
|
|
3
|
+
"version": "25.7.1",
|
|
4
4
|
"description": "Create an entire web theme.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"design",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"@web/test-runner-commands": "^0.9.0",
|
|
56
56
|
"@web/test-runner-playwright": "^0.11.0",
|
|
57
57
|
"@web/test-runner-visual-regression": "^0.10.0",
|
|
58
|
-
"element-book": "^25.7.
|
|
59
|
-
"element-vir": "^25.7.
|
|
58
|
+
"element-book": "^25.7.1",
|
|
59
|
+
"element-vir": "^25.7.1",
|
|
60
60
|
"esbuild": "^0.25.4",
|
|
61
61
|
"istanbul-smart-text-reporter": "^1.1.5",
|
|
62
62
|
"markdown-code-example-inserter": "^3.0.3",
|