@crewlethq/tokens 0.2.0 → 0.3.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/README.md +153 -20
- package/dist/css/base.css +194 -0
- package/dist/css/breakpoint.css +18 -0
- package/dist/css/density.css +23 -0
- package/dist/css/legacy.css +4 -6
- package/dist/css/material-symbols.css +5 -3
- package/dist/css/themes.css +338 -38
- package/dist/css/tokens.css +152 -38
- package/dist/index.d.ts +152 -12
- package/dist/index.js +152 -13
- package/dist/themes.d.ts +274 -0
- package/dist/themes.js +274 -0
- package/package.json +17 -5
- package/test/color.mjs +262 -0
- package/test/palette.d.mts +77 -0
- package/test/palette.mjs +867 -0
- package/test/palette.test.mjs +55 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The palette suite, over the CSS this package just built.
|
|
3
|
+
*
|
|
4
|
+
* The rules live in palette.mjs, which is published, so this file and a
|
|
5
|
+
* consumer's own suite measure the same table. What is here is the reading of
|
|
6
|
+
* dist/css in IMPORT order, the assertion, and two guards on the suite itself:
|
|
7
|
+
* a rule table that measured nothing would pass for any stylesheet.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { readFileSync } from 'node:fs';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
import assert from 'node:assert/strict';
|
|
13
|
+
import { describe, test } from 'node:test';
|
|
14
|
+
import { describeFailure, paletteStates, runPalette, tightest } from './palette.mjs';
|
|
15
|
+
|
|
16
|
+
const read = (name) => readFileSync(fileURLToPath(new URL(`../dist/css/${name}`, import.meta.url)), 'utf8');
|
|
17
|
+
// tokens.css first, themes.css second: they share the :root selector, neither
|
|
18
|
+
// adds specificity, and the later import is the one that paints.
|
|
19
|
+
const sources = { tokens: read('tokens.css'), themes: read('themes.css') };
|
|
20
|
+
|
|
21
|
+
describe('the palette', () => {
|
|
22
|
+
const { checks, failures } = runPalette(sources);
|
|
23
|
+
|
|
24
|
+
test('every rule holds in every theme state', (t) => {
|
|
25
|
+
for (const check of tightest(checks).sort((a, b) => a.rule.localeCompare(b.rule))) {
|
|
26
|
+
t.diagnostic(`tightest ${check.rule}: ${check.subject} (${check.state}) ${check.detail}`);
|
|
27
|
+
}
|
|
28
|
+
assert.deepEqual(failures.map(describeFailure), []);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('the suite measured what it claims to', () => {
|
|
32
|
+
// A rule table that read an empty token map would report no failures for
|
|
33
|
+
// any stylesheet at all, which is the one way this suite can lie.
|
|
34
|
+
const states = paletteStates(sources);
|
|
35
|
+
assert.deepEqual(Object.keys(states), ['base', 'light', 'dark (media query)', 'dark (attribute)']);
|
|
36
|
+
for (const [name, values] of Object.entries(states)) {
|
|
37
|
+
assert.ok(values.size > 80, `${name} resolved only ${values.size} tokens`);
|
|
38
|
+
assert.ok(values.has('--color-text-primary'), `${name} has no --color-text-primary`);
|
|
39
|
+
}
|
|
40
|
+
assert.notEqual(
|
|
41
|
+
states.light.get('--color-surface-background'),
|
|
42
|
+
states['dark (attribute)'].get('--color-surface-background'),
|
|
43
|
+
'the light and dark states resolved to the same page colour, so the theme blocks were not read',
|
|
44
|
+
);
|
|
45
|
+
assert.ok(checks.length > 400, `only ${checks.length} checks ran`);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('the theme layer wins over the token layer', () => {
|
|
49
|
+
// themes.css is imported second on purpose. If that ever stopped being
|
|
50
|
+
// true the light state would silently be the marketing palette.
|
|
51
|
+
const states = paletteStates(sources);
|
|
52
|
+
assert.equal(states.base.get('--color-surface-background'), '#000000');
|
|
53
|
+
assert.equal(states.light.get('--color-surface-background'), '#ffffff');
|
|
54
|
+
});
|
|
55
|
+
});
|