@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,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 };
|
|
@@ -0,0 +1,55 @@
|
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
19
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
20
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
21
|
+
}
|
|
22
|
+
Object.defineProperty(o, k2, desc);
|
|
23
|
+
}) : (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
}));
|
|
27
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
+
}) : function(o, v) {
|
|
30
|
+
o["default"] = v;
|
|
31
|
+
});
|
|
32
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.light = exports.themePropType = exports.schema = void 0;
|
|
41
|
+
const legacy = __importStar(require("./themes/legacy/light.js"));
|
|
42
|
+
var schema_js_1 = require("./themes/schema.js");
|
|
43
|
+
Object.defineProperty(exports, "schema", { enumerable: true, get: function () { return schema_js_1.schema; } });
|
|
44
|
+
var theme_prop_type_js_1 = require("./utils/theme-prop-type.js");
|
|
45
|
+
Object.defineProperty(exports, "themePropType", { enumerable: true, get: function () { return theme_prop_type_js_1.themePropType; } });
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated
|
|
48
|
+
*
|
|
49
|
+
* Use the CSS custom properties from `@sumup-oss/design-tokens` instead.
|
|
50
|
+
* Use the [`circuit-ui/prefer-custom-properties`](https://github.com/sumup-oss/circuit-ui/tree/main/packages/eslint-plugin-circuit-ui/prefer-custom-properties)
|
|
51
|
+
* ESLint rule to automatically migrate your code.
|
|
52
|
+
*/
|
|
53
|
+
// HACK: Copy the theme, otherwise, it gets exported as 'module'.
|
|
54
|
+
const light = { ...legacy };
|
|
55
|
+
exports.light = 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,182 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* Copyright 2023, SumUp Ltd.
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.validateTheme = validateTheme;
|
|
22
|
+
exports.createStyles = createStyles;
|
|
23
|
+
exports.createCSSCustomProperties = createCSSCustomProperties;
|
|
24
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
25
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
26
|
+
const browserslist_1 = __importDefault(require("browserslist"));
|
|
27
|
+
const lightningcss_1 = require("lightningcss");
|
|
28
|
+
const schema_js_1 = require("../themes/schema.js");
|
|
29
|
+
const shared_js_1 = require("../themes/shared.js");
|
|
30
|
+
const light_js_1 = require("../themes/light.js");
|
|
31
|
+
const dark_js_1 = require("../themes/dark.js");
|
|
32
|
+
function main() {
|
|
33
|
+
const themes = [
|
|
34
|
+
{
|
|
35
|
+
name: 'light',
|
|
36
|
+
groups: [
|
|
37
|
+
{
|
|
38
|
+
tokens: [...light_js_1.light, ...shared_js_1.shared],
|
|
39
|
+
selectors: [':root'],
|
|
40
|
+
colorScheme: 'light',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'dark',
|
|
46
|
+
groups: [
|
|
47
|
+
{
|
|
48
|
+
tokens: [...dark_js_1.dark, ...shared_js_1.shared],
|
|
49
|
+
selectors: [':root'],
|
|
50
|
+
colorScheme: 'dark',
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'light-scoped',
|
|
56
|
+
groups: [
|
|
57
|
+
{
|
|
58
|
+
tokens: light_js_1.light,
|
|
59
|
+
selectors: ['[data-color-scheme="light"]'],
|
|
60
|
+
colorScheme: 'light',
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'dark-scoped',
|
|
66
|
+
groups: [
|
|
67
|
+
{
|
|
68
|
+
tokens: dark_js_1.dark,
|
|
69
|
+
selectors: ['[data-color-scheme="dark"]'],
|
|
70
|
+
colorScheme: 'dark',
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'dynamic',
|
|
76
|
+
groups: [
|
|
77
|
+
{
|
|
78
|
+
tokens: [...light_js_1.light, ...shared_js_1.shared],
|
|
79
|
+
selectors: [':root'],
|
|
80
|
+
colorScheme: 'light',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
tokens: dark_js_1.dark,
|
|
84
|
+
selectors: ['@media (prefers-color-scheme: dark)', ':root'],
|
|
85
|
+
colorScheme: 'dark',
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
tokens: light_js_1.light,
|
|
89
|
+
selectors: ['[data-color-scheme="light"]'],
|
|
90
|
+
colorScheme: 'light',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
tokens: dark_js_1.dark,
|
|
94
|
+
selectors: ['[data-color-scheme="dark"]'],
|
|
95
|
+
colorScheme: 'dark',
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
const targets = (0, lightningcss_1.browserslistToTargets)((0, browserslist_1.default)());
|
|
101
|
+
themes.forEach((theme) => {
|
|
102
|
+
validateTheme(theme);
|
|
103
|
+
const filename = `${theme.name}.css`;
|
|
104
|
+
const filepath = node_path_1.default.join(__dirname, '../', filename);
|
|
105
|
+
const styles = theme.groups.map(createStyles).join('\n');
|
|
106
|
+
const { code } = (0, lightningcss_1.transform)({
|
|
107
|
+
filename,
|
|
108
|
+
code: Buffer.from(styles),
|
|
109
|
+
targets,
|
|
110
|
+
});
|
|
111
|
+
node_fs_1.default.writeFileSync(filepath, code, { flag: 'w' });
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Validates that the theme includes all expected tokens
|
|
116
|
+
* and that the token values match the expected type.
|
|
117
|
+
*/
|
|
118
|
+
function validateTheme(theme) {
|
|
119
|
+
// Validate the token types
|
|
120
|
+
theme.groups.forEach(({ tokens }) => {
|
|
121
|
+
tokens.forEach(({ name, type }) => {
|
|
122
|
+
const token = schema_js_1.schema.find((t) => t.name === name);
|
|
123
|
+
if (!token) {
|
|
124
|
+
return;
|
|
125
|
+
// throw new Error(`The theme is missing the required "${name}" token.`);
|
|
126
|
+
}
|
|
127
|
+
if (token.type !== type) {
|
|
128
|
+
throw new Error([
|
|
129
|
+
`The "${name}" token does not match the expected type.`,
|
|
130
|
+
`Expected "${token.type}". Received "${type}."`,
|
|
131
|
+
].join(' '));
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
// Validate that the tokens at the root are complete
|
|
136
|
+
const rootGroup = theme.groups.find((group) => group.selectors.length === 1 && group.selectors[0] === ':root');
|
|
137
|
+
if (!rootGroup) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (rootGroup.tokens.length !== schema_js_1.schema.length) {
|
|
141
|
+
schema_js_1.schema.forEach(({ name }) => {
|
|
142
|
+
const token = rootGroup.tokens.find((t) => t.name === name);
|
|
143
|
+
if (!token) {
|
|
144
|
+
throw new Error(`The "${theme.name}" theme does not globally define the required "${name}" token. Add it to the ":root" selector.`);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function createStyles(group) {
|
|
150
|
+
const selectorStart = group.selectors
|
|
151
|
+
.map((selector) => `${selector} {`)
|
|
152
|
+
.join('');
|
|
153
|
+
const selectorEnd = group.selectors.map(() => '}').join('');
|
|
154
|
+
const customProperties = createCSSCustomProperties(group.tokens);
|
|
155
|
+
return `${selectorStart}
|
|
156
|
+
color-scheme: ${group.colorScheme};
|
|
157
|
+
${customProperties}
|
|
158
|
+
${selectorEnd}`;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Generates CSS custom properties from the tokens
|
|
162
|
+
*/
|
|
163
|
+
function createCSSCustomProperties(tokens) {
|
|
164
|
+
return tokens
|
|
165
|
+
.flatMap((token) => {
|
|
166
|
+
const { description, name, value } = token;
|
|
167
|
+
const lines = [];
|
|
168
|
+
if (description) {
|
|
169
|
+
lines.push(`/* ${description} */`);
|
|
170
|
+
}
|
|
171
|
+
lines.push(`${name}: ${value.toString()};`);
|
|
172
|
+
return lines;
|
|
173
|
+
})
|
|
174
|
+
.join(' ');
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
main();
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
console.error(error.message);
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|