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 CHANGED
@@ -25,63 +25,91 @@ pnpm add dispersa
25
25
 
26
26
  ## Quick start
27
27
 
28
- Define a DTCG resolver document (`tokens.resolver.json`):
28
+ Define tokens inline and build CSS -- no files needed:
29
29
 
30
- ```json
31
- {
32
- "version": "2025.10",
33
- "sets": {
34
- "core": {
35
- "sources": [{ "$ref": "./tokens/base.json" }, { "$ref": "./tokens/alias.json" }]
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
- "modifiers": {
39
- "theme": {
40
- "default": "light",
41
- "contexts": {
42
- "light": [{ "$ref": "./tokens/themes/light.json" }],
43
- "dark": [{ "$ref": "./tokens/themes/dark.json" }]
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
- "resolutionOrder": [{ "$ref": "#/sets/core" }, { "$ref": "#/modifiers/theme" }]
90
+ resolutionOrder: [{ $ref: '#/sets/base' }, { $ref: '#/modifiers/theme' }],
48
91
  }
49
- ```
50
92
 
51
- Build tokens:
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
- if (result.success) {
81
- console.log(`Generated ${result.outputs.length} file(s)`)
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
- referenceTokens: void 0,
785
- ...options
784
+ ...options,
785
+ referenceTokens: options?.referenceTokens ?? tokens
786
786
  };
787
787
  const groups = this.groupTokens(tokens, opts);
788
- const referenceTokens = opts.referenceTokens ?? tokens;
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);