dispersa 0.1.2 → 0.1.3
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 +65 -37
- package/dist/builders.cjs +3 -3
- package/dist/builders.cjs.map +1 -1
- package/dist/builders.js +3 -3
- package/dist/builders.js.map +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,63 +25,91 @@ pnpm add dispersa
|
|
|
25
25
|
|
|
26
26
|
## Quick start
|
|
27
27
|
|
|
28
|
-
Define
|
|
28
|
+
Define tokens inline and build CSS -- no files needed:
|
|
29
29
|
|
|
30
|
-
```
|
|
31
|
-
{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
```typescript
|
|
31
|
+
import type { ResolverDocument } from 'dispersa'
|
|
32
|
+
import { Dispersa, css } from 'dispersa'
|
|
33
|
+
import { colorToHex, nameKebabCase } from 'dispersa/transforms'
|
|
34
|
+
|
|
35
|
+
const resolver: ResolverDocument = {
|
|
36
|
+
version: '2025.10',
|
|
37
|
+
sets: {
|
|
38
|
+
base: {
|
|
39
|
+
sources: [
|
|
40
|
+
{
|
|
41
|
+
color: {
|
|
42
|
+
brand: {
|
|
43
|
+
primary: {
|
|
44
|
+
$type: 'color',
|
|
45
|
+
$value: { colorSpace: 'srgb', components: [0, 0.4, 0.8] },
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
neutral: {
|
|
49
|
+
white: {
|
|
50
|
+
$type: 'color',
|
|
51
|
+
$value: { colorSpace: 'srgb', components: [1, 1, 1] },
|
|
52
|
+
},
|
|
53
|
+
black: {
|
|
54
|
+
$type: 'color',
|
|
55
|
+
$value: { colorSpace: 'srgb', components: [0, 0, 0] },
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
spacing: {
|
|
60
|
+
small: { $type: 'dimension', $value: { value: 8, unit: 'px' } },
|
|
61
|
+
medium: { $type: 'dimension', $value: { value: 16, unit: 'px' } },
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
37
66
|
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
67
|
+
modifiers: {
|
|
68
|
+
theme: {
|
|
69
|
+
default: 'light',
|
|
70
|
+
contexts: {
|
|
71
|
+
light: [
|
|
72
|
+
{
|
|
73
|
+
semantic: {
|
|
74
|
+
background: { $type: 'color', $value: '{color.neutral.white}' },
|
|
75
|
+
text: { $type: 'color', $value: '{color.neutral.black}' },
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
dark: [
|
|
80
|
+
{
|
|
81
|
+
semantic: {
|
|
82
|
+
background: { $type: 'color', $value: '{color.neutral.black}' },
|
|
83
|
+
text: { $type: 'color', $value: '{color.neutral.white}' },
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
},
|
|
46
89
|
},
|
|
47
|
-
|
|
90
|
+
resolutionOrder: [{ $ref: '#/sets/base' }, { $ref: '#/modifiers/theme' }],
|
|
48
91
|
}
|
|
49
|
-
```
|
|
50
92
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
import { Dispersa, css, json } from 'dispersa'
|
|
55
|
-
import { colorToHex, nameKebabCase } from 'dispersa/transforms'
|
|
56
|
-
|
|
57
|
-
const dispersa = new Dispersa({
|
|
58
|
-
resolver: './tokens.resolver.json',
|
|
59
|
-
buildPath: './dist',
|
|
60
|
-
})
|
|
93
|
+
const dispersa = new Dispersa({ resolver })
|
|
61
94
|
|
|
62
95
|
const result = await dispersa.build({
|
|
63
96
|
outputs: [
|
|
64
97
|
css({
|
|
65
98
|
name: 'css',
|
|
66
|
-
file: 'tokens.css',
|
|
67
99
|
preset: 'bundle',
|
|
68
100
|
selector: ':root',
|
|
69
101
|
transforms: [nameKebabCase(), colorToHex()],
|
|
70
102
|
}),
|
|
71
|
-
json({
|
|
72
|
-
name: 'json',
|
|
73
|
-
file: 'tokens-{theme}.json',
|
|
74
|
-
preset: 'standalone',
|
|
75
|
-
structure: 'flat',
|
|
76
|
-
}),
|
|
77
103
|
],
|
|
78
104
|
})
|
|
79
105
|
|
|
80
|
-
|
|
81
|
-
console.log(
|
|
106
|
+
for (const output of result.outputs) {
|
|
107
|
+
console.log(output.content)
|
|
82
108
|
}
|
|
83
109
|
```
|
|
84
110
|
|
|
111
|
+
> For file-based tokens, define JSON files and reference them with `$ref` in your resolver document. See the [`basic` example](./examples/basic/) for a complete setup.
|
|
112
|
+
|
|
85
113
|
## Output formats
|
|
86
114
|
|
|
87
115
|
Dispersa ships four builder functions. Each returns an `OutputConfig` that can be passed to `build()`.
|
package/dist/builders.cjs
CHANGED
|
@@ -781,11 +781,11 @@ var CssRenderer = class _CssRenderer {
|
|
|
781
781
|
mediaQuery: "",
|
|
782
782
|
minify: false,
|
|
783
783
|
preserveReferences: false,
|
|
784
|
-
|
|
785
|
-
|
|
784
|
+
...options,
|
|
785
|
+
referenceTokens: options?.referenceTokens ?? tokens
|
|
786
786
|
};
|
|
787
787
|
const groups = this.groupTokens(tokens, opts);
|
|
788
|
-
const referenceTokens = opts.referenceTokens
|
|
788
|
+
const referenceTokens = opts.referenceTokens;
|
|
789
789
|
const lines = [];
|
|
790
790
|
for (const [selector, groupTokens] of Object.entries(groups)) {
|
|
791
791
|
this.buildCssBlock(lines, groupTokens, selector, tokens, referenceTokens, opts);
|