@sumup-oss/design-tokens 8.0.0-next.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/LICENSE +201 -0
- package/README.md +115 -0
- package/dark-scoped.css +140 -0
- package/dark.css +201 -0
- package/dist/cjs/index.d.ts +27 -0
- package/dist/cjs/index.js +55 -0
- package/dist/cjs/scripts/build.d.ts +36 -0
- package/dist/cjs/scripts/build.js +182 -0
- package/dist/cjs/themes/dark.d.ts +555 -0
- package/dist/cjs/themes/dark.js +694 -0
- package/dist/cjs/themes/legacy/light.d.ts +85 -0
- package/dist/cjs/themes/legacy/light.js +196 -0
- package/dist/cjs/themes/light.d.ts +555 -0
- package/dist/cjs/themes/light.js +694 -0
- package/dist/cjs/themes/schema.d.ts +603 -0
- package/dist/cjs/themes/schema.js +243 -0
- package/dist/cjs/themes/shared.d.ts +259 -0
- package/dist/cjs/themes/shared.js +333 -0
- package/dist/cjs/types/index.d.ts +175 -0
- package/dist/cjs/types/index.js +16 -0
- package/dist/cjs/utils/theme-prop-type.d.ts +36 -0
- package/dist/cjs/utils/theme-prop-type.js +162 -0
- package/dist/es/index.d.ts +27 -0
- package/dist/es/index.js +27 -0
- package/dist/es/scripts/build.d.ts +36 -0
- package/dist/es/scripts/build.js +174 -0
- package/dist/es/themes/dark.d.ts +555 -0
- package/dist/es/themes/dark.js +691 -0
- package/dist/es/themes/legacy/light.d.ts +85 -0
- package/dist/es/themes/legacy/light.js +193 -0
- package/dist/es/themes/light.d.ts +555 -0
- package/dist/es/themes/light.js +691 -0
- package/dist/es/themes/schema.d.ts +603 -0
- package/dist/es/themes/schema.js +240 -0
- package/dist/es/themes/shared.d.ts +259 -0
- package/dist/es/themes/shared.js +330 -0
- package/dist/es/types/index.d.ts +175 -0
- package/dist/es/types/index.js +15 -0
- package/dist/es/utils/theme-prop-type.d.ts +36 -0
- package/dist/es/utils/theme-prop-type.js +156 -0
- package/dynamic.css +626 -0
- package/light-scoped.css +140 -0
- package/light.css +201 -0
- package/package.json +44 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2020, SumUp Ltd.
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.themePropType = void 0;
|
|
21
|
+
const prop_types_1 = __importDefault(require("prop-types"));
|
|
22
|
+
const typePropType = prop_types_1.default.shape({
|
|
23
|
+
fontSize: prop_types_1.default.string,
|
|
24
|
+
lineHeight: prop_types_1.default.string,
|
|
25
|
+
}).isRequired;
|
|
26
|
+
const gridPropType = prop_types_1.default.shape({
|
|
27
|
+
priority: prop_types_1.default.number.isRequired,
|
|
28
|
+
breakpoint: prop_types_1.default.oneOf([
|
|
29
|
+
'default',
|
|
30
|
+
'untilKilo',
|
|
31
|
+
'kilo',
|
|
32
|
+
'mega',
|
|
33
|
+
'giga',
|
|
34
|
+
'tera',
|
|
35
|
+
]).isRequired,
|
|
36
|
+
cols: prop_types_1.default.number.isRequired,
|
|
37
|
+
maxWidth: prop_types_1.default.string.isRequired,
|
|
38
|
+
gutter: prop_types_1.default.string.isRequired,
|
|
39
|
+
}).isRequired;
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated
|
|
42
|
+
*
|
|
43
|
+
* Use the CSS custom properties from `@sumup-oss/design-tokens` instead.
|
|
44
|
+
* Use the [`circuit-ui/prefer-custom-properties`](https://github.com/sumup-oss/circuit-ui/tree/main/packages/eslint-plugin-circuit-ui/prefer-custom-properties)
|
|
45
|
+
* ESLint rule to automatically migrate your code.
|
|
46
|
+
*/
|
|
47
|
+
exports.themePropType = prop_types_1.default.shape({
|
|
48
|
+
spacings: prop_types_1.default.shape({
|
|
49
|
+
bit: prop_types_1.default.string.isRequired,
|
|
50
|
+
byte: prop_types_1.default.string.isRequired,
|
|
51
|
+
kilo: prop_types_1.default.string.isRequired,
|
|
52
|
+
mega: prop_types_1.default.string.isRequired,
|
|
53
|
+
giga: prop_types_1.default.string.isRequired,
|
|
54
|
+
tera: prop_types_1.default.string.isRequired,
|
|
55
|
+
peta: prop_types_1.default.string.isRequired,
|
|
56
|
+
exa: prop_types_1.default.string.isRequired,
|
|
57
|
+
zetta: prop_types_1.default.string.isRequired,
|
|
58
|
+
})
|
|
59
|
+
.isRequired,
|
|
60
|
+
iconSizes: prop_types_1.default.shape({
|
|
61
|
+
kilo: prop_types_1.default.string.isRequired,
|
|
62
|
+
mega: prop_types_1.default.string.isRequired,
|
|
63
|
+
giga: prop_types_1.default.string.isRequired,
|
|
64
|
+
tera: prop_types_1.default.string.isRequired,
|
|
65
|
+
})
|
|
66
|
+
.isRequired,
|
|
67
|
+
borderRadius: prop_types_1.default.shape({
|
|
68
|
+
bit: prop_types_1.default.string.isRequired,
|
|
69
|
+
byte: prop_types_1.default.string.isRequired,
|
|
70
|
+
kilo: prop_types_1.default.string.isRequired,
|
|
71
|
+
mega: prop_types_1.default.string.isRequired,
|
|
72
|
+
circle: prop_types_1.default.string.isRequired,
|
|
73
|
+
pill: prop_types_1.default.string.isRequired,
|
|
74
|
+
})
|
|
75
|
+
.isRequired,
|
|
76
|
+
borderWidth: prop_types_1.default.shape({
|
|
77
|
+
kilo: prop_types_1.default.string.isRequired,
|
|
78
|
+
mega: prop_types_1.default.string.isRequired,
|
|
79
|
+
})
|
|
80
|
+
.isRequired,
|
|
81
|
+
typography: prop_types_1.default.shape({
|
|
82
|
+
headline: prop_types_1.default.shape({
|
|
83
|
+
one: typePropType,
|
|
84
|
+
two: typePropType,
|
|
85
|
+
three: typePropType,
|
|
86
|
+
four: typePropType,
|
|
87
|
+
}).isRequired,
|
|
88
|
+
title: prop_types_1.default.shape({
|
|
89
|
+
one: typePropType,
|
|
90
|
+
two: typePropType,
|
|
91
|
+
three: typePropType,
|
|
92
|
+
four: typePropType,
|
|
93
|
+
}).isRequired,
|
|
94
|
+
subHeadline: typePropType,
|
|
95
|
+
body: prop_types_1.default.shape({
|
|
96
|
+
one: typePropType,
|
|
97
|
+
two: typePropType,
|
|
98
|
+
}).isRequired,
|
|
99
|
+
bodyLarge: typePropType,
|
|
100
|
+
}).isRequired,
|
|
101
|
+
fontStack: prop_types_1.default.shape({
|
|
102
|
+
default: prop_types_1.default.string,
|
|
103
|
+
mono: prop_types_1.default.string,
|
|
104
|
+
}).isRequired,
|
|
105
|
+
fontWeight: prop_types_1.default.shape({
|
|
106
|
+
regular: prop_types_1.default.string.isRequired,
|
|
107
|
+
bold: prop_types_1.default.string.isRequired,
|
|
108
|
+
})
|
|
109
|
+
.isRequired,
|
|
110
|
+
breakpoints: prop_types_1.default.shape({
|
|
111
|
+
untilKilo: prop_types_1.default.string.isRequired,
|
|
112
|
+
kilo: prop_types_1.default.string.isRequired,
|
|
113
|
+
kiloToMega: prop_types_1.default.string.isRequired,
|
|
114
|
+
mega: prop_types_1.default.string.isRequired,
|
|
115
|
+
untilMega: prop_types_1.default.string.isRequired,
|
|
116
|
+
megaToGiga: prop_types_1.default.string.isRequired,
|
|
117
|
+
giga: prop_types_1.default.string.isRequired,
|
|
118
|
+
untilGiga: prop_types_1.default.string.isRequired,
|
|
119
|
+
gigaToTera: prop_types_1.default.string.isRequired,
|
|
120
|
+
tera: prop_types_1.default.string.isRequired,
|
|
121
|
+
untilTera: prop_types_1.default.string.isRequired,
|
|
122
|
+
})
|
|
123
|
+
.isRequired,
|
|
124
|
+
mq: prop_types_1.default.shape({
|
|
125
|
+
untilKilo: prop_types_1.default.string.isRequired,
|
|
126
|
+
kilo: prop_types_1.default.string.isRequired,
|
|
127
|
+
kiloToMega: prop_types_1.default.string.isRequired,
|
|
128
|
+
mega: prop_types_1.default.string.isRequired,
|
|
129
|
+
untilMega: prop_types_1.default.string.isRequired,
|
|
130
|
+
megaToGiga: prop_types_1.default.string.isRequired,
|
|
131
|
+
giga: prop_types_1.default.string.isRequired,
|
|
132
|
+
gigaToTera: prop_types_1.default.string.isRequired,
|
|
133
|
+
tera: prop_types_1.default.string.isRequired,
|
|
134
|
+
untilTera: prop_types_1.default.string.isRequired,
|
|
135
|
+
})
|
|
136
|
+
.isRequired,
|
|
137
|
+
grid: prop_types_1.default.shape({
|
|
138
|
+
default: gridPropType,
|
|
139
|
+
untilKilo: gridPropType,
|
|
140
|
+
kilo: gridPropType,
|
|
141
|
+
mega: gridPropType,
|
|
142
|
+
giga: gridPropType,
|
|
143
|
+
tera: gridPropType,
|
|
144
|
+
}).isRequired,
|
|
145
|
+
transitions: prop_types_1.default.shape({
|
|
146
|
+
default: prop_types_1.default.string.isRequired,
|
|
147
|
+
slow: prop_types_1.default.string.isRequired,
|
|
148
|
+
})
|
|
149
|
+
.isRequired,
|
|
150
|
+
zIndex: prop_types_1.default.shape({
|
|
151
|
+
default: prop_types_1.default.number.isRequired,
|
|
152
|
+
absolute: prop_types_1.default.number.isRequired,
|
|
153
|
+
input: prop_types_1.default.number.isRequired,
|
|
154
|
+
popover: prop_types_1.default.number.isRequired,
|
|
155
|
+
tooltip: prop_types_1.default.number.isRequired,
|
|
156
|
+
header: prop_types_1.default.number.isRequired,
|
|
157
|
+
backdrop: prop_types_1.default.number.isRequired,
|
|
158
|
+
navigation: prop_types_1.default.number.isRequired,
|
|
159
|
+
modal: prop_types_1.default.number.isRequired,
|
|
160
|
+
toast: prop_types_1.default.number.isRequired,
|
|
161
|
+
}).isRequired,
|
|
162
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2020, SumUp Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
import type { Theme } from './types/index.js';
|
|
16
|
+
export { schema } from './themes/schema.js';
|
|
17
|
+
export { themePropType } from './utils/theme-prop-type.js';
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated
|
|
20
|
+
*
|
|
21
|
+
* Use the CSS custom properties from `@sumup-oss/design-tokens` instead.
|
|
22
|
+
* Use the [`circuit-ui/prefer-custom-properties`](https://github.com/sumup-oss/circuit-ui/tree/main/packages/eslint-plugin-circuit-ui/prefer-custom-properties)
|
|
23
|
+
* ESLint rule to automatically migrate your code.
|
|
24
|
+
*/
|
|
25
|
+
declare const light: Theme;
|
|
26
|
+
export type { Theme };
|
|
27
|
+
export { light };
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2020, SumUp Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
import * as legacy from './themes/legacy/light.js';
|
|
16
|
+
export { schema } from './themes/schema.js';
|
|
17
|
+
export { themePropType } from './utils/theme-prop-type.js';
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated
|
|
20
|
+
*
|
|
21
|
+
* Use the CSS custom properties from `@sumup-oss/design-tokens` instead.
|
|
22
|
+
* Use the [`circuit-ui/prefer-custom-properties`](https://github.com/sumup-oss/circuit-ui/tree/main/packages/eslint-plugin-circuit-ui/prefer-custom-properties)
|
|
23
|
+
* ESLint rule to automatically migrate your code.
|
|
24
|
+
*/
|
|
25
|
+
// HACK: Copy the theme, otherwise, it gets exported as 'module'.
|
|
26
|
+
const light = { ...legacy };
|
|
27
|
+
export { light };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2023, SumUp Ltd.
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { ColorScheme, Token } from '../types/index.js';
|
|
17
|
+
type StyleGroup = {
|
|
18
|
+
selectors: string[];
|
|
19
|
+
colorScheme: ColorScheme;
|
|
20
|
+
tokens: Token[];
|
|
21
|
+
};
|
|
22
|
+
type Theme = {
|
|
23
|
+
name: string;
|
|
24
|
+
groups: StyleGroup[];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Validates that the theme includes all expected tokens
|
|
28
|
+
* and that the token values match the expected type.
|
|
29
|
+
*/
|
|
30
|
+
export declare function validateTheme(theme: Theme): void;
|
|
31
|
+
export declare function createStyles(group: StyleGroup): string;
|
|
32
|
+
/**
|
|
33
|
+
* Generates CSS custom properties from the tokens
|
|
34
|
+
*/
|
|
35
|
+
export declare function createCSSCustomProperties(tokens: Token[]): string;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2023, SumUp Ltd.
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import fs from 'node:fs';
|
|
17
|
+
import path from 'node:path';
|
|
18
|
+
import browserslist from 'browserslist';
|
|
19
|
+
import { transform, browserslistToTargets } from 'lightningcss';
|
|
20
|
+
import { schema } from '../themes/schema.js';
|
|
21
|
+
import { shared } from '../themes/shared.js';
|
|
22
|
+
import { light } from '../themes/light.js';
|
|
23
|
+
import { dark } from '../themes/dark.js';
|
|
24
|
+
function main() {
|
|
25
|
+
const themes = [
|
|
26
|
+
{
|
|
27
|
+
name: 'light',
|
|
28
|
+
groups: [
|
|
29
|
+
{
|
|
30
|
+
tokens: [...light, ...shared],
|
|
31
|
+
selectors: [':root'],
|
|
32
|
+
colorScheme: 'light',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'dark',
|
|
38
|
+
groups: [
|
|
39
|
+
{
|
|
40
|
+
tokens: [...dark, ...shared],
|
|
41
|
+
selectors: [':root'],
|
|
42
|
+
colorScheme: 'dark',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'light-scoped',
|
|
48
|
+
groups: [
|
|
49
|
+
{
|
|
50
|
+
tokens: light,
|
|
51
|
+
selectors: ['[data-color-scheme="light"]'],
|
|
52
|
+
colorScheme: 'light',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'dark-scoped',
|
|
58
|
+
groups: [
|
|
59
|
+
{
|
|
60
|
+
tokens: dark,
|
|
61
|
+
selectors: ['[data-color-scheme="dark"]'],
|
|
62
|
+
colorScheme: 'dark',
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'dynamic',
|
|
68
|
+
groups: [
|
|
69
|
+
{
|
|
70
|
+
tokens: [...light, ...shared],
|
|
71
|
+
selectors: [':root'],
|
|
72
|
+
colorScheme: 'light',
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
tokens: dark,
|
|
76
|
+
selectors: ['@media (prefers-color-scheme: dark)', ':root'],
|
|
77
|
+
colorScheme: 'dark',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
tokens: light,
|
|
81
|
+
selectors: ['[data-color-scheme="light"]'],
|
|
82
|
+
colorScheme: 'light',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
tokens: dark,
|
|
86
|
+
selectors: ['[data-color-scheme="dark"]'],
|
|
87
|
+
colorScheme: 'dark',
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
];
|
|
92
|
+
const targets = browserslistToTargets(browserslist());
|
|
93
|
+
themes.forEach((theme) => {
|
|
94
|
+
validateTheme(theme);
|
|
95
|
+
const filename = `${theme.name}.css`;
|
|
96
|
+
const filepath = path.join(__dirname, '../', filename);
|
|
97
|
+
const styles = theme.groups.map(createStyles).join('\n');
|
|
98
|
+
const { code } = transform({
|
|
99
|
+
filename,
|
|
100
|
+
code: Buffer.from(styles),
|
|
101
|
+
targets,
|
|
102
|
+
});
|
|
103
|
+
fs.writeFileSync(filepath, code, { flag: 'w' });
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Validates that the theme includes all expected tokens
|
|
108
|
+
* and that the token values match the expected type.
|
|
109
|
+
*/
|
|
110
|
+
export function validateTheme(theme) {
|
|
111
|
+
// Validate the token types
|
|
112
|
+
theme.groups.forEach(({ tokens }) => {
|
|
113
|
+
tokens.forEach(({ name, type }) => {
|
|
114
|
+
const token = schema.find((t) => t.name === name);
|
|
115
|
+
if (!token) {
|
|
116
|
+
return;
|
|
117
|
+
// throw new Error(`The theme is missing the required "${name}" token.`);
|
|
118
|
+
}
|
|
119
|
+
if (token.type !== type) {
|
|
120
|
+
throw new Error([
|
|
121
|
+
`The "${name}" token does not match the expected type.`,
|
|
122
|
+
`Expected "${token.type}". Received "${type}."`,
|
|
123
|
+
].join(' '));
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
// Validate that the tokens at the root are complete
|
|
128
|
+
const rootGroup = theme.groups.find((group) => group.selectors.length === 1 && group.selectors[0] === ':root');
|
|
129
|
+
if (!rootGroup) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (rootGroup.tokens.length !== schema.length) {
|
|
133
|
+
schema.forEach(({ name }) => {
|
|
134
|
+
const token = rootGroup.tokens.find((t) => t.name === name);
|
|
135
|
+
if (!token) {
|
|
136
|
+
throw new Error(`The "${theme.name}" theme does not globally define the required "${name}" token. Add it to the ":root" selector.`);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export function createStyles(group) {
|
|
142
|
+
const selectorStart = group.selectors
|
|
143
|
+
.map((selector) => `${selector} {`)
|
|
144
|
+
.join('');
|
|
145
|
+
const selectorEnd = group.selectors.map(() => '}').join('');
|
|
146
|
+
const customProperties = createCSSCustomProperties(group.tokens);
|
|
147
|
+
return `${selectorStart}
|
|
148
|
+
color-scheme: ${group.colorScheme};
|
|
149
|
+
${customProperties}
|
|
150
|
+
${selectorEnd}`;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Generates CSS custom properties from the tokens
|
|
154
|
+
*/
|
|
155
|
+
export function createCSSCustomProperties(tokens) {
|
|
156
|
+
return tokens
|
|
157
|
+
.flatMap((token) => {
|
|
158
|
+
const { description, name, value } = token;
|
|
159
|
+
const lines = [];
|
|
160
|
+
if (description) {
|
|
161
|
+
lines.push(`/* ${description} */`);
|
|
162
|
+
}
|
|
163
|
+
lines.push(`${name}: ${value.toString()};`);
|
|
164
|
+
return lines;
|
|
165
|
+
})
|
|
166
|
+
.join(' ');
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
main();
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
console.error(error.message);
|
|
173
|
+
process.exit(1);
|
|
174
|
+
}
|