theme-vir 28.19.0 → 28.20.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.
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ColorThemeOverride } from './color-theme-init.js';
|
|
2
|
+
import { type ColorTheme } from './color-theme.js';
|
|
3
|
+
/**
|
|
4
|
+
* Create the `<style>` id used to apply color themes globally by {@link applyGlobalColorTheme}.
|
|
5
|
+
*
|
|
6
|
+
* @category Internal
|
|
7
|
+
*/
|
|
8
|
+
export declare function createGlobalThemeStyleId(colorTheme: Readonly<ColorTheme>): string;
|
|
9
|
+
/**
|
|
10
|
+
* Create the global `<style>` element used by {@link applyGlobalColorTheme} to apply a color theme.
|
|
11
|
+
*
|
|
12
|
+
* @category Internal
|
|
13
|
+
*/
|
|
14
|
+
export declare function createGlobalThemeStyleElement(colorTheme: Readonly<ColorTheme>, context?: Element): HTMLStyleElement;
|
|
15
|
+
/**
|
|
16
|
+
* Sets all of a color theme's CSS vars in a global style element. If no override is given, the
|
|
17
|
+
* theme color default values are assigned.
|
|
18
|
+
*
|
|
19
|
+
* @category Color Theme
|
|
20
|
+
*/
|
|
21
|
+
export declare function applyGlobalColorTheme(fullTheme: ColorTheme, themeOverride?: ColorThemeOverride | undefined): void;
|
|
22
|
+
/**
|
|
23
|
+
* A very inefficient way of setting all of a color theme's CSS vars on a given element. If no
|
|
24
|
+
* override is given, the theme color default values are assigned.
|
|
25
|
+
*
|
|
26
|
+
* @deprecated Use {@link applyGlobalColorTheme} instead whenever possible.
|
|
27
|
+
* @category Internal
|
|
28
|
+
*/
|
|
29
|
+
export declare function applyColorTheme(
|
|
30
|
+
/** This should usually be the top-level `html` element. */
|
|
31
|
+
element: HTMLElement, fullTheme: ColorTheme, themeOverride?: ColorThemeOverride | undefined): void;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { camelCaseToKebabCase, getObjectTypedValues } from '@augment-vir/common';
|
|
2
|
+
import { setCssVarValue } from 'lit-css-vars';
|
|
3
|
+
/**
|
|
4
|
+
* Create the `<style>` id used to apply color themes globally by {@link applyGlobalColorTheme}.
|
|
5
|
+
*
|
|
6
|
+
* @category Internal
|
|
7
|
+
*/
|
|
8
|
+
export function createGlobalThemeStyleId(colorTheme) {
|
|
9
|
+
return [
|
|
10
|
+
camelCaseToKebabCase(colorTheme.prefix),
|
|
11
|
+
'global-theme-vir-style',
|
|
12
|
+
].join('-');
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create the global `<style>` element used by {@link applyGlobalColorTheme} to apply a color theme.
|
|
16
|
+
*
|
|
17
|
+
* @category Internal
|
|
18
|
+
*/
|
|
19
|
+
export function createGlobalThemeStyleElement(colorTheme, context = document.head) {
|
|
20
|
+
const styleId = createGlobalThemeStyleId(colorTheme);
|
|
21
|
+
const existingElement = context.querySelector(`style#${styleId}`);
|
|
22
|
+
if (existingElement instanceof HTMLStyleElement) {
|
|
23
|
+
return existingElement;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const newStyleElement = globalThis.document.createElement('style');
|
|
27
|
+
newStyleElement.id = styleId;
|
|
28
|
+
context.append(newStyleElement);
|
|
29
|
+
return newStyleElement;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Sets all of a color theme's CSS vars in a global style element. If no override is given, the
|
|
34
|
+
* theme color default values are assigned.
|
|
35
|
+
*
|
|
36
|
+
* @category Color Theme
|
|
37
|
+
*/
|
|
38
|
+
export function applyGlobalColorTheme(fullTheme, themeOverride) {
|
|
39
|
+
const styleElement = createGlobalThemeStyleElement(fullTheme);
|
|
40
|
+
const cssVarDeclarations = getObjectTypedValues(fullTheme.colors).flatMap((themeColor) => {
|
|
41
|
+
return [
|
|
42
|
+
buildCssVarDeclaration({
|
|
43
|
+
layerKey: 'background',
|
|
44
|
+
themeColor,
|
|
45
|
+
themeOverride,
|
|
46
|
+
}),
|
|
47
|
+
buildCssVarDeclaration({
|
|
48
|
+
layerKey: 'foreground',
|
|
49
|
+
themeColor,
|
|
50
|
+
themeOverride,
|
|
51
|
+
}),
|
|
52
|
+
];
|
|
53
|
+
});
|
|
54
|
+
styleElement.textContent = `:root {\n ${cssVarDeclarations.join('\n ')}\n}`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A very inefficient way of setting all of a color theme's CSS vars on a given element. If no
|
|
58
|
+
* override is given, the theme color default values are assigned.
|
|
59
|
+
*
|
|
60
|
+
* @deprecated Use {@link applyGlobalColorTheme} instead whenever possible.
|
|
61
|
+
* @category Internal
|
|
62
|
+
*/
|
|
63
|
+
export function applyColorTheme(
|
|
64
|
+
/** This should usually be the top-level `html` element. */
|
|
65
|
+
element, fullTheme, themeOverride) {
|
|
66
|
+
getObjectTypedValues(fullTheme.colors).forEach((themeColor) => {
|
|
67
|
+
applyIndividualThemeColorValue({
|
|
68
|
+
element,
|
|
69
|
+
layerKey: 'background',
|
|
70
|
+
themeColor,
|
|
71
|
+
themeOverride,
|
|
72
|
+
});
|
|
73
|
+
applyIndividualThemeColorValue({
|
|
74
|
+
element,
|
|
75
|
+
layerKey: 'foreground',
|
|
76
|
+
themeColor,
|
|
77
|
+
themeOverride,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function buildCssVarDeclaration({ layerKey, themeOverride, themeColor, }) {
|
|
82
|
+
const override = themeOverride?.overrides[String(themeColor[layerKey].name)];
|
|
83
|
+
const value = override || themeColor[layerKey].default;
|
|
84
|
+
return `${themeColor[layerKey].name}: ${value};`;
|
|
85
|
+
}
|
|
86
|
+
function applyIndividualThemeColorValue({ element, layerKey, themeOverride, themeColor, }) {
|
|
87
|
+
const override = themeOverride?.overrides[String(themeColor[layerKey].name)];
|
|
88
|
+
const value = override || themeColor[layerKey].default;
|
|
89
|
+
setCssVarValue({
|
|
90
|
+
forCssVar: themeColor[layerKey],
|
|
91
|
+
onElement: element,
|
|
92
|
+
toValue: value,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
@@ -2,7 +2,7 @@ import { type RequiredAndNotNull, type Values } from '@augment-vir/common';
|
|
|
2
2
|
import { CSSResult } from 'element-vir';
|
|
3
3
|
import { type CssVarName, type SingleCssVarDefinition } from 'lit-css-vars';
|
|
4
4
|
import { type RequireAtLeastOne } from 'type-fest';
|
|
5
|
-
import { type ColorInit, type ColorInitReference, type ColorInitValue, type ColorThemeInit
|
|
5
|
+
import { type ColorInit, type ColorInitReference, type ColorInitValue, type ColorThemeInit } from './color-theme-init.js';
|
|
6
6
|
/**
|
|
7
7
|
* Same as {@link ColorInit} but without references.
|
|
8
8
|
*
|
|
@@ -40,6 +40,7 @@ export type ColorTheme<Init extends ColorThemeInit = ColorThemeInit> = {
|
|
|
40
40
|
colors: Init;
|
|
41
41
|
default: Readonly<DefaultColorThemeInit>;
|
|
42
42
|
};
|
|
43
|
+
prefix: string;
|
|
43
44
|
};
|
|
44
45
|
/**
|
|
45
46
|
* All colors within a {@link ColorTheme}.
|
|
@@ -74,15 +75,6 @@ export type DefaultColorThemeInit = RequiredAndNotNull<NoRefColorInit> & {
|
|
|
74
75
|
* @category Internal
|
|
75
76
|
*/
|
|
76
77
|
export declare const themeDefaultKey = "theme-default";
|
|
77
|
-
/**
|
|
78
|
-
* Set all color theme CSS vars on the given element. If no override is given, the theme color
|
|
79
|
-
* default values are assigned.
|
|
80
|
-
*
|
|
81
|
-
* @category Color Theme
|
|
82
|
-
*/
|
|
83
|
-
export declare function applyColorTheme<const Theme extends ColorTheme>(
|
|
84
|
-
/** This should usually be the top-level `html` element. */
|
|
85
|
-
element: HTMLElement, fullTheme: Theme, themeOverride?: ColorThemeOverride | undefined): void;
|
|
86
78
|
/**
|
|
87
79
|
* Define a color theme.
|
|
88
80
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assert, check } from '@augment-vir/assert';
|
|
2
|
-
import { getObjectTypedEntries,
|
|
2
|
+
import { getObjectTypedEntries, log, } from '@augment-vir/common';
|
|
3
3
|
import { CSSResult } from 'element-vir';
|
|
4
|
-
import { defineCssVars,
|
|
4
|
+
import { defineCssVars, } from 'lit-css-vars';
|
|
5
5
|
/** @category Internal */
|
|
6
6
|
export function noRefColorInitToString(init) {
|
|
7
7
|
if (check.isPrimitive(init) || init instanceof CSSResult) {
|
|
@@ -57,39 +57,6 @@ export function createColorCssVarDefault(fromName, init, defaultInit, colorsInit
|
|
|
57
57
|
* @category Internal
|
|
58
58
|
*/
|
|
59
59
|
export const themeDefaultKey = 'theme-default';
|
|
60
|
-
/**
|
|
61
|
-
* Set all color theme CSS vars on the given element. If no override is given, the theme color
|
|
62
|
-
* default values are assigned.
|
|
63
|
-
*
|
|
64
|
-
* @category Color Theme
|
|
65
|
-
*/
|
|
66
|
-
export function applyColorTheme(
|
|
67
|
-
/** This should usually be the top-level `html` element. */
|
|
68
|
-
element, fullTheme, themeOverride) {
|
|
69
|
-
getObjectTypedValues(fullTheme.colors).forEach((themeColor) => {
|
|
70
|
-
applyIndividualThemeColorValue({
|
|
71
|
-
element,
|
|
72
|
-
layerKey: 'background',
|
|
73
|
-
themeColor,
|
|
74
|
-
themeOverride,
|
|
75
|
-
});
|
|
76
|
-
applyIndividualThemeColorValue({
|
|
77
|
-
element,
|
|
78
|
-
layerKey: 'foreground',
|
|
79
|
-
themeColor,
|
|
80
|
-
themeOverride,
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function applyIndividualThemeColorValue({ element, layerKey, themeOverride, themeColor, }) {
|
|
85
|
-
const override = themeOverride?.overrides[String(themeColor[layerKey].name)];
|
|
86
|
-
const value = override || themeColor[layerKey].default;
|
|
87
|
-
setCssVarValue({
|
|
88
|
-
forCssVar: themeColor[layerKey],
|
|
89
|
-
onElement: element,
|
|
90
|
-
toValue: value,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
60
|
/**
|
|
94
61
|
* Define a color theme.
|
|
95
62
|
*
|
|
@@ -193,6 +160,7 @@ export function defineColorTheme(defaultInit, allColorsInit) {
|
|
|
193
160
|
colors: allColorsInit,
|
|
194
161
|
default: defaultInit,
|
|
195
162
|
},
|
|
163
|
+
prefix: defaultInit.prefix,
|
|
196
164
|
};
|
|
197
165
|
}
|
|
198
166
|
catch (error) {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "theme-vir",
|
|
3
|
-
"version": "28.
|
|
3
|
+
"version": "28.20.0",
|
|
4
4
|
"description": "Create an entire web theme.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"design",
|
|
@@ -43,15 +43,15 @@
|
|
|
43
43
|
"test:update": "virmator test web update"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@augment-vir/assert": "^31.59.
|
|
47
|
-
"@augment-vir/common": "^31.59.
|
|
46
|
+
"@augment-vir/assert": "^31.59.2",
|
|
47
|
+
"@augment-vir/common": "^31.59.2",
|
|
48
48
|
"@electrovir/color": "^1.7.8",
|
|
49
49
|
"apca-w3": "^0.1.9",
|
|
50
50
|
"lit-css-vars": "^3.4.0",
|
|
51
51
|
"type-fest": "^5.4.1"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@augment-vir/test": "^31.59.
|
|
54
|
+
"@augment-vir/test": "^31.59.2",
|
|
55
55
|
"@types/apca-w3": "^0.1.3",
|
|
56
56
|
"@web/dev-server-esbuild": "^1.0.4",
|
|
57
57
|
"@web/test-runner": "^0.20.2",
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
"@web/test-runner-visual-regression": "^0.10.0",
|
|
61
61
|
"element-book": "^26.16.0",
|
|
62
62
|
"element-vir": "^26.14.3",
|
|
63
|
-
"esbuild": "^0.27.
|
|
63
|
+
"esbuild": "^0.27.3",
|
|
64
64
|
"istanbul-smart-text-reporter": "^1.1.5",
|
|
65
65
|
"markdown-code-example-inserter": "^3.0.3",
|
|
66
66
|
"typedoc": "^0.28.16",
|
|
67
67
|
"typescript": "5.9.3",
|
|
68
|
-
"vira": "^29.
|
|
68
|
+
"vira": "^29.3.0",
|
|
69
69
|
"vite": "^7.3.1",
|
|
70
70
|
"vite-tsconfig-paths": "^6.0.5"
|
|
71
71
|
},
|