dispersa 0.1.2 → 0.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Dispersa
2
2
 
3
- A TypeScript build system for processing [DTCG 2025.10](https://www.designtokens.org/) design tokens. Dispersa loads resolver documents, resolves references and modifiers, applies filters and transforms, then renders output to CSS, JSON, and JS/TS modules.
3
+ A TypeScript build system for processing [DTCG 2025.10](https://www.designtokens.org/) design tokens. Dispersa loads resolver documents, resolves references and modifiers, applies filters and transforms, then renders output to CSS, JSON, JS/TS or custom modules.
4
4
 
5
5
  ## Features
6
6
 
@@ -17,71 +17,109 @@ A TypeScript build system for processing [DTCG 2025.10](https://www.designtokens
17
17
 
18
18
  **Composite types:** `shadow`, `typography`, `border`, `strokeStyle`, `transition`, `gradient`
19
19
 
20
- ## Installation
20
+ ## Getting started
21
+
22
+ ### New project
21
23
 
22
24
  ```bash
23
- pnpm add dispersa
25
+ pnpm create dispersa
24
26
  ```
25
27
 
26
- ## Quick start
28
+ The scaffold prompts for a project directory, lets you pick a template (programmatic or CLI-based), and optionally installs dependencies.
27
29
 
28
- Define a DTCG resolver document (`tokens.resolver.json`):
30
+ ### Add to an existing project
29
31
 
30
- ```json
31
- {
32
- "version": "2025.10",
33
- "sets": {
34
- "core": {
35
- "sources": [{ "$ref": "./tokens/base.json" }, { "$ref": "./tokens/alias.json" }]
36
- }
37
- },
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
- }
46
- },
47
- "resolutionOrder": [{ "$ref": "#/sets/core" }, { "$ref": "#/modifiers/theme" }]
48
- }
32
+ ```bash
33
+ pnpm add dispersa
49
34
  ```
50
35
 
51
- Build tokens:
36
+ ## Quick start
37
+
38
+ Define tokens inline and build CSS -- no files needed:
52
39
 
53
40
  ```typescript
54
- import { Dispersa, css, json } from 'dispersa'
41
+ import type { ResolverDocument } from 'dispersa'
42
+ import { Dispersa, css } from 'dispersa'
55
43
  import { colorToHex, nameKebabCase } from 'dispersa/transforms'
56
44
 
57
- const dispersa = new Dispersa({
58
- resolver: './tokens.resolver.json',
59
- buildPath: './dist',
60
- })
45
+ const resolver: ResolverDocument = {
46
+ version: '2025.10',
47
+ sets: {
48
+ base: {
49
+ sources: [
50
+ {
51
+ color: {
52
+ brand: {
53
+ primary: {
54
+ $type: 'color',
55
+ $value: { colorSpace: 'srgb', components: [0, 0.4, 0.8] },
56
+ },
57
+ },
58
+ neutral: {
59
+ white: {
60
+ $type: 'color',
61
+ $value: { colorSpace: 'srgb', components: [1, 1, 1] },
62
+ },
63
+ black: {
64
+ $type: 'color',
65
+ $value: { colorSpace: 'srgb', components: [0, 0, 0] },
66
+ },
67
+ },
68
+ },
69
+ spacing: {
70
+ small: { $type: 'dimension', $value: { value: 8, unit: 'px' } },
71
+ medium: { $type: 'dimension', $value: { value: 16, unit: 'px' } },
72
+ },
73
+ },
74
+ ],
75
+ },
76
+ },
77
+ modifiers: {
78
+ theme: {
79
+ default: 'light',
80
+ contexts: {
81
+ light: [
82
+ {
83
+ semantic: {
84
+ background: { $type: 'color', $value: '{color.neutral.white}' },
85
+ text: { $type: 'color', $value: '{color.neutral.black}' },
86
+ },
87
+ },
88
+ ],
89
+ dark: [
90
+ {
91
+ semantic: {
92
+ background: { $type: 'color', $value: '{color.neutral.black}' },
93
+ text: { $type: 'color', $value: '{color.neutral.white}' },
94
+ },
95
+ },
96
+ ],
97
+ },
98
+ },
99
+ },
100
+ resolutionOrder: [{ $ref: '#/sets/base' }, { $ref: '#/modifiers/theme' }],
101
+ }
102
+
103
+ const dispersa = new Dispersa({ resolver })
61
104
 
62
105
  const result = await dispersa.build({
63
106
  outputs: [
64
107
  css({
65
108
  name: 'css',
66
- file: 'tokens.css',
67
109
  preset: 'bundle',
68
110
  selector: ':root',
69
111
  transforms: [nameKebabCase(), colorToHex()],
70
112
  }),
71
- json({
72
- name: 'json',
73
- file: 'tokens-{theme}.json',
74
- preset: 'standalone',
75
- structure: 'flat',
76
- }),
77
113
  ],
78
114
  })
79
115
 
80
- if (result.success) {
81
- console.log(`Generated ${result.outputs.length} file(s)`)
116
+ for (const output of result.outputs) {
117
+ console.log(output.content)
82
118
  }
83
119
  ```
84
120
 
121
+ > 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.
122
+
85
123
  ## Output formats
86
124
 
87
125
  Dispersa ships four builder functions. Each returns an `OutputConfig` that can be passed to `build()`.
@@ -133,6 +171,12 @@ Renders JavaScript/TypeScript modules.
133
171
  | `transforms` | `Transform[]` | -- | Per-output transforms |
134
172
  | `filters` | `Filter[]` | -- | Per-output filters |
135
173
 
174
+ ### Experimental: native platform outputs
175
+
176
+ Dispersa also ships `ios()` and `android()` builders for Swift/SwiftUI and Kotlin/Jetpack Compose. These are **experimental** -- APIs and generated code may change.
177
+
178
+ See the [multi-platform example](./examples/multi-platform/) for a complete setup.
179
+
136
180
  ## Output presets
137
181
 
138
182
  Presets control how modifier permutations are packaged into files.
@@ -630,10 +674,10 @@ All hooks support both sync and async functions.
630
674
 
631
675
  ## CLI
632
676
 
633
- Dispersa ships a CLI package (`dispersa-cli`) with a config-first workflow.
677
+ Dispersa includes a CLI for a config-first workflow.
634
678
 
635
679
  ```bash
636
- pnpm add dispersa-cli
680
+ pnpm add dispersa
637
681
  ```
638
682
 
639
683
  ```bash
@@ -645,7 +689,7 @@ The CLI auto-discovers config files named `dispersa.config.(ts|js|mts|mjs|cts|cj
645
689
 
646
690
  ```typescript
647
691
  // dispersa.config.ts
648
- import { defineConfig } from 'dispersa-cli'
692
+ import { defineConfig } from 'dispersa/config'
649
693
  import { css, json } from 'dispersa'
650
694
  import { colorToHex, nameKebabCase } from 'dispersa/transforms'
651
695