@designtools/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 +11 -5
- package/dist/{chunk-T62MMGGQ.js → chunk-3OG7U5V2.js} +57 -4
- package/dist/cli.js +16 -50
- package/dist/index.d.ts +110 -4
- package/dist/index.js +37 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -136,9 +136,10 @@ Supported by `css`, `tailwind-v4` and `json`; the other formats reject it rather
|
|
|
136
136
|
| `--format` | `css` · `tailwind-v4` · `tailwind-v3` · `dtcg` · `json` · `all` | `css` | Serialiser. `all` writes every format into `--out` as a directory. |
|
|
137
137
|
| `--color-format` | `oklch` · `hex` · `rgb` · `hsl` | `oklch` | How literal colour values are printed. |
|
|
138
138
|
| `--out <path>` | — | stdout | File to write, or a directory when `--format all`. |
|
|
139
|
-
| `--replace-palette` | flag | off | `tailwind-v4` only —
|
|
139
|
+
| `--no-replace-palette` | flag | off | `tailwind-v4` only — keep Tailwind's stock palette. See [Overriding Tailwind's palette](#overriding-tailwinds-palette). |
|
|
140
140
|
| `--no-provenance` | flag | off | Omit the `Generated by …` header. |
|
|
141
|
-
| `--vanilla` | flag | — | Accepted and ignored; removed in 0.
|
|
141
|
+
| `--vanilla` | flag | — | Accepted and ignored; removed in 0.4. |
|
|
142
|
+
| `--replace-palette` | flag | — | Accepted and ignored; this is the default from 0.3. |
|
|
142
143
|
|
|
143
144
|
File names under `--format all`: `tokens.css`, `tailwind.css`, `tailwind.config.js`, `tokens.dtcg.json`, `tokens.json`.
|
|
144
145
|
|
|
@@ -209,15 +210,19 @@ Verified against a real Tailwind v4 compile and in a browser: `bg-primary` and `
|
|
|
209
210
|
|
|
210
211
|
The generated ramps deliberately override Tailwind's stock ones, so `text-red-500` is the project's red. The instinct is to withhold primitives so people are pushed toward semantics, but that is the wrong failure mode: if a project does not own `--color-red-500`, then `text-red-500` yields Tailwind's stock red — off-brand, compiles cleanly, looks deliberate in review, and survives a re-theme. Emitting them makes the accident harmless.
|
|
211
212
|
|
|
212
|
-
|
|
213
|
+
Overriding only the ramps the generator emits would leave ~17 stock hues intact, so `bg-slate-900` would stay available and off-brand. **From 0.3 the generated theme clears the whole namespace by default:**
|
|
213
214
|
|
|
214
215
|
```css
|
|
215
216
|
@theme static { --color-*: initial; }
|
|
216
217
|
```
|
|
217
218
|
|
|
218
|
-
Any
|
|
219
|
+
Any colour class the file does not define then fails to compile rather than rendering wrong. That is the point: an off-brand class becomes a build error you fix, instead of a shade nobody chose that reviews cleanly and survives a re-theme.
|
|
219
220
|
|
|
220
|
-
|
|
221
|
+
The reset is emitted before the definitions, so it clears Tailwind's palette without touching the one just defined. Verified against a real compile: `bg-primary`, `bg-primary-500`, `bg-red-500` (the project's red) and `bg-black`/`bg-white` all compile, `bg-slate-900` fails. Tailwind's `transparent`, `current` and `inherit` are **not** part of the `--color-*` theme namespace, so `bg-transparent` and `text-current` keep working.
|
|
222
|
+
|
|
223
|
+
Pass `--no-replace-palette` when adopting the generator into an existing Tailwind codebase that still uses stock hues — otherwise every `bg-slate-*` in the project stops compiling at once.
|
|
224
|
+
|
|
225
|
+
## Migrating from 0.1 / 0.2
|
|
221
226
|
|
|
222
227
|
0.2 changes generated output. Existing projects will see their drift checks fail once; regenerate to adopt.
|
|
223
228
|
|
|
@@ -229,6 +234,7 @@ Any stock colour class then fails to compile rather than compiling wrong. It is
|
|
|
229
234
|
| `tailwind-v4` restructured | Regenerate. The dark selector is now `[data-theme="dark"], .dark` rather than `.dark` alone, and there is now a `prefers-color-scheme` fallback matching the css export. |
|
|
230
235
|
| `tailwind-v4` primitives renamed | `--primary-500` → `--color-primary-500`, matching the css export. Update any direct references. |
|
|
231
236
|
| Output carries a provenance header | Expected. `--no-provenance` opts out. |
|
|
237
|
+
| **0.3:** `tailwind-v4` clears Tailwind's stock palette by default | Stock hues like `bg-slate-900` now fail to compile. Intended — see above. Pass `--no-replace-palette` to keep them, and `--replace-palette` is now a no-op. |
|
|
232
238
|
| A seed outside 15–98% lightness no longer inverts the ramp | Bug fix. A near-black or near-white seed was reproduced exactly at its anchor while its neighbours were clamped, so 500 could come out darker than 600. The range now widens to admit the seed; the tight side collapses onto it instead. Only affects seeds outside that range. |
|
|
233
239
|
|
|
234
240
|
The plain-CSS, `tailwind-v3` and `dtcg` outputs are otherwise unchanged apart from the header and the removed aliases.
|
|
@@ -1086,7 +1086,7 @@ function emitTailwindV4Mode(tokens, mode, colorFormat, shadeOverrides, aliases,
|
|
|
1086
1086
|
lines.push(...emitThemeRebinding(aliases, indent));
|
|
1087
1087
|
return lines;
|
|
1088
1088
|
}
|
|
1089
|
-
function exportToTailwindV4(tokens, colorFormat = "hex", shadeOverrides, replacePalette =
|
|
1089
|
+
function exportToTailwindV4(tokens, colorFormat = "hex", shadeOverrides, replacePalette = true, sections, shades) {
|
|
1090
1090
|
const lines = [];
|
|
1091
1091
|
const active = resolveShades(shades);
|
|
1092
1092
|
const want = sectionSet(sections);
|
|
@@ -1095,7 +1095,8 @@ function exportToTailwindV4(tokens, colorFormat = "hex", shadeOverrides, replace
|
|
|
1095
1095
|
const wantModes = aliases.length > 0;
|
|
1096
1096
|
lines.push("@theme static {");
|
|
1097
1097
|
if (replacePalette) {
|
|
1098
|
-
lines.push(" /* Clear Tailwind's stock palette
|
|
1098
|
+
lines.push(" /* Clear Tailwind's stock palette, so a colour class this file does not");
|
|
1099
|
+
lines.push(" define fails to compile instead of silently rendering off-brand. */");
|
|
1099
1100
|
lines.push(" --color-*: initial;");
|
|
1100
1101
|
lines.push("");
|
|
1101
1102
|
}
|
|
@@ -1316,7 +1317,7 @@ function selectTokenSections(tokens, sections) {
|
|
|
1316
1317
|
function exportTokens(tokens, format, options) {
|
|
1317
1318
|
const colorFormat = options?.colorFormat ?? "hex";
|
|
1318
1319
|
const shadeOverrides = options?.shadeOverrides;
|
|
1319
|
-
const replacePalette = options?.replacePalette
|
|
1320
|
+
const replacePalette = options?.replacePalette !== false;
|
|
1320
1321
|
const sections = options?.sections;
|
|
1321
1322
|
const shades = options?.shades;
|
|
1322
1323
|
if (sections && sections.length > 0 && !SECTIONED_FORMATS.includes(format)) {
|
|
@@ -1338,11 +1339,56 @@ function exportTokens(tokens, format, options) {
|
|
|
1338
1339
|
}
|
|
1339
1340
|
}
|
|
1340
1341
|
|
|
1342
|
+
// src/seed.ts
|
|
1343
|
+
var GENERATOR_NAME = "@designtools/tokens";
|
|
1344
|
+
function stableStringify(value) {
|
|
1345
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "null";
|
|
1346
|
+
if (Array.isArray(value)) return `[${value.map(stableStringify).join(",")}]`;
|
|
1347
|
+
const entries = Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${stableStringify(v)}`);
|
|
1348
|
+
return `{${entries.join(",")}}`;
|
|
1349
|
+
}
|
|
1350
|
+
function fingerprint(input) {
|
|
1351
|
+
let h = 2166136261;
|
|
1352
|
+
for (let i = 0; i < input.length; i++) {
|
|
1353
|
+
h ^= input.charCodeAt(i);
|
|
1354
|
+
h = Math.imul(h, 16777619) >>> 0;
|
|
1355
|
+
}
|
|
1356
|
+
return h.toString(16).padStart(8, "0");
|
|
1357
|
+
}
|
|
1358
|
+
function seedFingerprint(config) {
|
|
1359
|
+
return fingerprint(stableStringify(config));
|
|
1360
|
+
}
|
|
1361
|
+
function provenanceComment(p) {
|
|
1362
|
+
return `/* Generated by ${GENERATOR_NAME} v${p.version} (seed ${p.seed}) - do not edit by hand */`;
|
|
1363
|
+
}
|
|
1364
|
+
var PROVENANCE_RE = new RegExp(
|
|
1365
|
+
`${GENERATOR_NAME.replace("/", "\\/")} v(\\S+) \\(seed ([0-9a-f]{8})\\)`
|
|
1366
|
+
);
|
|
1367
|
+
function parseProvenance(text) {
|
|
1368
|
+
const comment = PROVENANCE_RE.exec(text);
|
|
1369
|
+
if (comment) return { version: comment[1], seed: comment[2] };
|
|
1370
|
+
const json = /"\$designtools"\s*:\s*\{[^}]*"version"\s*:\s*"([^"]+)"[^}]*"seed"\s*:\s*"([0-9a-f]{8})"/.exec(text);
|
|
1371
|
+
if (json) return { version: json[1], seed: json[2] };
|
|
1372
|
+
return null;
|
|
1373
|
+
}
|
|
1374
|
+
function withJsonProvenance(json, p) {
|
|
1375
|
+
const parsed = JSON.parse(json);
|
|
1376
|
+
const stamped = {
|
|
1377
|
+
$designtools: { generator: GENERATOR_NAME, version: p.version, seed: p.seed },
|
|
1378
|
+
...parsed
|
|
1379
|
+
};
|
|
1380
|
+
return JSON.stringify(stamped, null, 2);
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1341
1383
|
export {
|
|
1342
1384
|
VALID_SHADES,
|
|
1385
|
+
DEFAULT_SEED_SHADE,
|
|
1386
|
+
TAILWIND_SHADES,
|
|
1343
1387
|
SHADE_PRESETS,
|
|
1344
1388
|
resolveShades,
|
|
1345
1389
|
snapShade,
|
|
1390
|
+
reanchorFactors,
|
|
1391
|
+
chromaShadeFor,
|
|
1346
1392
|
parseToOklch,
|
|
1347
1393
|
oklchToHex,
|
|
1348
1394
|
generateColorScale,
|
|
@@ -1377,5 +1423,12 @@ export {
|
|
|
1377
1423
|
exportToDtcg,
|
|
1378
1424
|
SECTIONED_FORMATS,
|
|
1379
1425
|
selectTokenSections,
|
|
1380
|
-
exportTokens
|
|
1426
|
+
exportTokens,
|
|
1427
|
+
GENERATOR_NAME,
|
|
1428
|
+
stableStringify,
|
|
1429
|
+
fingerprint,
|
|
1430
|
+
seedFingerprint,
|
|
1431
|
+
provenanceComment,
|
|
1432
|
+
parseProvenance,
|
|
1433
|
+
withJsonProvenance
|
|
1381
1434
|
};
|
package/dist/cli.js
CHANGED
|
@@ -10,60 +10,21 @@ import {
|
|
|
10
10
|
computeAccessibilityScore,
|
|
11
11
|
exportTokens,
|
|
12
12
|
generateTokens,
|
|
13
|
+
parseProvenance,
|
|
13
14
|
parseToOklch,
|
|
15
|
+
provenanceComment,
|
|
14
16
|
resolveShades,
|
|
17
|
+
seedFingerprint,
|
|
15
18
|
selectTokenSections,
|
|
16
|
-
snapShade
|
|
17
|
-
|
|
19
|
+
snapShade,
|
|
20
|
+
withJsonProvenance
|
|
21
|
+
} from "./chunk-3OG7U5V2.js";
|
|
18
22
|
|
|
19
23
|
// src/cli.ts
|
|
20
24
|
import { parseArgs } from "util";
|
|
21
25
|
import { mkdirSync, writeFileSync, readFileSync, statSync } from "fs";
|
|
22
26
|
import { join, dirname } from "path";
|
|
23
27
|
import { fileURLToPath } from "url";
|
|
24
|
-
|
|
25
|
-
// src/seed.ts
|
|
26
|
-
var GENERATOR_NAME = "@designtools/tokens";
|
|
27
|
-
function stableStringify(value) {
|
|
28
|
-
if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "null";
|
|
29
|
-
if (Array.isArray(value)) return `[${value.map(stableStringify).join(",")}]`;
|
|
30
|
-
const entries = Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${stableStringify(v)}`);
|
|
31
|
-
return `{${entries.join(",")}}`;
|
|
32
|
-
}
|
|
33
|
-
function fingerprint(input) {
|
|
34
|
-
let h = 2166136261;
|
|
35
|
-
for (let i = 0; i < input.length; i++) {
|
|
36
|
-
h ^= input.charCodeAt(i);
|
|
37
|
-
h = Math.imul(h, 16777619) >>> 0;
|
|
38
|
-
}
|
|
39
|
-
return h.toString(16).padStart(8, "0");
|
|
40
|
-
}
|
|
41
|
-
function seedFingerprint(config) {
|
|
42
|
-
return fingerprint(stableStringify(config));
|
|
43
|
-
}
|
|
44
|
-
function provenanceComment(p) {
|
|
45
|
-
return `/* Generated by ${GENERATOR_NAME} v${p.version} (seed ${p.seed}) - do not edit by hand */`;
|
|
46
|
-
}
|
|
47
|
-
var PROVENANCE_RE = new RegExp(
|
|
48
|
-
`${GENERATOR_NAME.replace("/", "\\/")} v(\\S+) \\(seed ([0-9a-f]{8})\\)`
|
|
49
|
-
);
|
|
50
|
-
function parseProvenance(text) {
|
|
51
|
-
const comment = PROVENANCE_RE.exec(text);
|
|
52
|
-
if (comment) return { version: comment[1], seed: comment[2] };
|
|
53
|
-
const json = /"\$designtools"\s*:\s*\{[^}]*"version"\s*:\s*"([^"]+)"[^}]*"seed"\s*:\s*"([0-9a-f]{8})"/.exec(text);
|
|
54
|
-
if (json) return { version: json[1], seed: json[2] };
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
function withJsonProvenance(json, p) {
|
|
58
|
-
const parsed = JSON.parse(json);
|
|
59
|
-
const stamped = {
|
|
60
|
-
$designtools: { generator: GENERATOR_NAME, version: p.version, seed: p.seed },
|
|
61
|
-
...parsed
|
|
62
|
-
};
|
|
63
|
-
return JSON.stringify(stamped, null, 2);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/cli.ts
|
|
67
28
|
var HELP = `generate-tokens \u2014 brand colour in, design tokens out
|
|
68
29
|
|
|
69
30
|
Usage:
|
|
@@ -119,10 +80,14 @@ Output:
|
|
|
119
80
|
switch off are gone in 0.2, so vanilla is now the only
|
|
120
81
|
behaviour. Kept for one version so existing calls do not
|
|
121
82
|
break; it will be removed in 0.3.
|
|
122
|
-
--replace-palette
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
83
|
+
--no-replace-palette tailwind-v4 only: keep Tailwind's stock colour palette.
|
|
84
|
+
By default the generated theme clears it
|
|
85
|
+
(--color-*: initial), so a colour class this tool does
|
|
86
|
+
not define fails to compile rather than silently
|
|
87
|
+
rendering off-brand. Pass this when adopting the
|
|
88
|
+
generator into an existing Tailwind codebase that still
|
|
89
|
+
uses stock hues like bg-slate-900.
|
|
90
|
+
--replace-palette Accepted and ignored; this is the default in 0.3.
|
|
126
91
|
--no-provenance Omit the "Generated by \u2026" header. The header is what
|
|
127
92
|
makes --check able to distinguish a generator upgrade
|
|
128
93
|
from a hand edit, so dropping it costs you that.
|
|
@@ -182,6 +147,7 @@ try {
|
|
|
182
147
|
out: { type: "string" },
|
|
183
148
|
vanilla: { type: "boolean" },
|
|
184
149
|
"replace-palette": { type: "boolean" },
|
|
150
|
+
"no-replace-palette": { type: "boolean" },
|
|
185
151
|
seed: { type: "string" },
|
|
186
152
|
check: { type: "boolean" },
|
|
187
153
|
report: { type: "boolean" },
|
|
@@ -351,7 +317,7 @@ if (shades) {
|
|
|
351
317
|
}
|
|
352
318
|
}
|
|
353
319
|
}
|
|
354
|
-
var replacePalette = values["replace-palette"]
|
|
320
|
+
var replacePalette = values["no-replace-palette"] !== true;
|
|
355
321
|
var resolvedSeed = {
|
|
356
322
|
primaryColor: primary,
|
|
357
323
|
neutralColor: neutral,
|
package/dist/index.d.ts
CHANGED
|
@@ -423,9 +423,10 @@ interface ExportOptions {
|
|
|
423
423
|
colorFormat?: ColorFormat;
|
|
424
424
|
shadeOverrides?: SemanticShadeOverrides;
|
|
425
425
|
/**
|
|
426
|
-
* Clear Tailwind's stock colour palette in the tailwind-v4 export, so
|
|
427
|
-
*
|
|
428
|
-
*
|
|
426
|
+
* Clear Tailwind's stock colour palette in the tailwind-v4 export, so a colour
|
|
427
|
+
* class the generator does not define fails to compile rather than compiling
|
|
428
|
+
* off-brand. Default: true. Set false to keep the stock hues available, which
|
|
429
|
+
* an existing Tailwind codebase adopting the generator will need.
|
|
429
430
|
*/
|
|
430
431
|
replacePalette?: boolean;
|
|
431
432
|
/**
|
|
@@ -439,9 +440,114 @@ interface ExportOptions {
|
|
|
439
440
|
*/
|
|
440
441
|
shades?: readonly ShadeNumber[];
|
|
441
442
|
}
|
|
443
|
+
/** Formats whose structure lets a section filter be applied meaningfully */
|
|
444
|
+
declare const SECTIONED_FORMATS: ExportFormat[];
|
|
445
|
+
/**
|
|
446
|
+
* Narrow a TokenSystem to the requested sections, for the `json` output.
|
|
447
|
+
*
|
|
448
|
+
* Colour only: the spacing, typography, radii and shadow tiers are carried
|
|
449
|
+
* through untouched when the full system is requested, and dropped otherwise.
|
|
450
|
+
*/
|
|
451
|
+
declare function selectTokenSections(tokens: TokenSystem, sections?: TokenSection[]): Partial<TokenSystem>;
|
|
442
452
|
/**
|
|
443
453
|
* Export tokens in the specified format
|
|
444
454
|
*/
|
|
445
455
|
declare function exportTokens(tokens: TokenSystem, format: ExportFormat, options?: ExportOptions): string;
|
|
446
456
|
|
|
447
|
-
|
|
457
|
+
/**
|
|
458
|
+
* Shade-set utilities: which steps a ramp emits, and where the seed sits on it.
|
|
459
|
+
*
|
|
460
|
+
* Two independent knobs:
|
|
461
|
+
* - `seedShade` — which step the input colour lands on. It was pinned to 500,
|
|
462
|
+
* which wrecks the ramp when a brand colour arrives as a deep navy or a pale
|
|
463
|
+
* tint, since everything else is derived from headroom either side of it.
|
|
464
|
+
* - `shades` — which steps get emitted at all. Ours is 25–950; Tailwind's stock
|
|
465
|
+
* ramps are 50–950, and matching that makes the palette override cleaner.
|
|
466
|
+
*/
|
|
467
|
+
|
|
468
|
+
/** Where the seed sits when nobody says otherwise */
|
|
469
|
+
declare const DEFAULT_SEED_SHADE: ShadeNumber;
|
|
470
|
+
/** Tailwind's stock ramp: 50–950, no 25 */
|
|
471
|
+
declare const TAILWIND_SHADES: ShadeNumber[];
|
|
472
|
+
/** Named shade-set presets accepted by --shades */
|
|
473
|
+
declare const SHADE_PRESETS: Record<string, ShadeNumber[]>;
|
|
474
|
+
/** Normalise a requested shade set: valid, de-duplicated, light-to-dark */
|
|
475
|
+
declare function resolveShades(requested?: readonly ShadeNumber[]): ShadeNumber[];
|
|
476
|
+
/**
|
|
477
|
+
* Nearest emitted shade to the one a token asked for.
|
|
478
|
+
*
|
|
479
|
+
* Semantic, surface and utility tokens name specific steps (muted sits on 25,
|
|
480
|
+
* borders on neutral-200). When --shades drops one of those, the reference has
|
|
481
|
+
* to move somewhere real or the output ships a var() pointing at nothing.
|
|
482
|
+
* Distance is measured in ramp positions, not shade numbers, so the steps count
|
|
483
|
+
* evenly. Ties go to the darker step, which is the safer direction for the
|
|
484
|
+
* foregrounds and borders this mostly affects.
|
|
485
|
+
*/
|
|
486
|
+
declare function snapShade(shade: ShadeNumber, active: readonly ShadeNumber[]): ShadeNumber;
|
|
487
|
+
/**
|
|
488
|
+
* Re-anchor a lightness-factor table so the seed lands on `seedShade`.
|
|
489
|
+
*
|
|
490
|
+
* The table is signed: positive entries are a fraction of the headroom above the
|
|
491
|
+
* seed, negative a fraction of the headroom below, and the anchor is 0. Moving
|
|
492
|
+
* the anchor changes how many steps sit either side of it, so each side's curve
|
|
493
|
+
* is resampled onto its new slot count. That keeps the ramp's perceptual shape —
|
|
494
|
+
* gentle at the light end, larger jumps at the dark end for text contrast —
|
|
495
|
+
* rather than stretching one uniform gradient.
|
|
496
|
+
*
|
|
497
|
+
* A side left with a single slot reaches that curve's extreme, since that one
|
|
498
|
+
* step stands in for the whole remaining range.
|
|
499
|
+
*/
|
|
500
|
+
declare function reanchorFactors(base: readonly number[], seedShade: ShadeNumber): number[];
|
|
501
|
+
/**
|
|
502
|
+
* Shade whose chroma envelope a given ramp position should borrow.
|
|
503
|
+
*
|
|
504
|
+
* Chroma peaks around the middle of the ramp. With the anchor moved, using each
|
|
505
|
+
* step's own shade number would put peak chroma at 500 while the seed's exact
|
|
506
|
+
* colour sits elsewhere, leaving a visible discontinuity at the anchor. Shifting
|
|
507
|
+
* the envelope by the same amount as the anchor keeps the seed at the peak.
|
|
508
|
+
*/
|
|
509
|
+
declare function chromaShadeFor(index: number, seedShade: ShadeNumber): ShadeNumber;
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Seed capture and provenance.
|
|
513
|
+
*
|
|
514
|
+
* A seed file is a `SavedConfig` — the same shape the web tool persists — so the
|
|
515
|
+
* two can hand work to each other without a second format. The provenance header
|
|
516
|
+
* records the generator version and a fingerprint of the resolved seed, which is
|
|
517
|
+
* what lets `--check` tell "you upgraded the generator" apart from "someone
|
|
518
|
+
* hand-edited the output".
|
|
519
|
+
*
|
|
520
|
+
* No imports on purpose: this stays usable in a browser alongside the rest of
|
|
521
|
+
* the library, and the dependency list stays culori + apca-w3.
|
|
522
|
+
*/
|
|
523
|
+
|
|
524
|
+
declare const GENERATOR_NAME = "@designtools/tokens";
|
|
525
|
+
/** A seed file is a partial SavedConfig — every field has a CLI default. */
|
|
526
|
+
type SeedFile = Partial<SavedConfig>;
|
|
527
|
+
/**
|
|
528
|
+
* Deterministic JSON with object keys sorted, so two configs that differ only
|
|
529
|
+
* in key order fingerprint identically.
|
|
530
|
+
*/
|
|
531
|
+
declare function stableStringify(value: unknown): string;
|
|
532
|
+
/**
|
|
533
|
+
* FNV-1a, 32-bit, as eight hex digits.
|
|
534
|
+
*
|
|
535
|
+
* A change-detection fingerprint, not a security hash — it only has to make an
|
|
536
|
+
* accidental edit to the seed visible, and it keeps this module dependency-free
|
|
537
|
+
* and identical across platforms.
|
|
538
|
+
*/
|
|
539
|
+
declare function fingerprint(input: string): string;
|
|
540
|
+
/** Fingerprint of a resolved seed configuration */
|
|
541
|
+
declare function seedFingerprint(config: SeedFile): string;
|
|
542
|
+
interface Provenance {
|
|
543
|
+
version: string;
|
|
544
|
+
seed: string;
|
|
545
|
+
}
|
|
546
|
+
/** The one-line header stamped onto generated CSS and JS output */
|
|
547
|
+
declare function provenanceComment(p: Provenance): string;
|
|
548
|
+
/** Read provenance back out of previously generated output, in any format */
|
|
549
|
+
declare function parseProvenance(text: string): Provenance | null;
|
|
550
|
+
/** Attach provenance to a JSON document as a `$designtools` key */
|
|
551
|
+
declare function withJsonProvenance(json: string, p: Provenance): string;
|
|
552
|
+
|
|
553
|
+
export { type APCAContrastResult, type BrandColors, type CVDType, type ColorFormat, type ColorScale, type ContrastAlgorithm, type ContrastTarget, DEFAULT_NEUTRAL_COLOR, DEFAULT_SEED_SHADE, type ExportFormat, type ExportOptions, type ExtendedSemanticColor, type ForegroundRef, GENERATOR_NAME, type GenerationOptions, type LightnessStrategy, type PrimitivePalette, type Provenance, SECTIONED_FORMATS, SHADE_PRESETS, type SavedConfig, type ScaleOptions, type SeedFile, type SemanticColorPair, type SemanticShadeOverrides, type SemanticTokens, type ShadeNumber, type SurfaceRef, type SurfaceShadeOverrides, type SurfaceTokens, TAILWIND_SHADES, TOKEN_SECTIONS, type TokenSection, type TokenSystem, type UtilityShadeOverrides, type UtilityTokens, VALID_SHADES, type VariantShadeOverrides, type WCAGContrastResult, adjustChroma, adjustLightness, checkSemanticContrast, checkSemanticContrastAPCA, chromaShadeFor, classifyAPCALevel, computeAccessibilityScore, exportToCss, exportToDtcg, exportToTailwindV3, exportToTailwindV4, exportTokens, findContrastingColorAPCA, fingerprint, formatColorAs, formatColorShort, generateColorScale, generateColorScaleAPCA, generatePrimitivePalette, generateSemanticTokens, generateSurfaceTokens, generateTokens, generateUtilityTokens, getAPCAContrast, getContrastRatio, getOklchString, getRelativeLuminance, getShade, meetsWCAG_AA, meetsWCAG_AAA, oklchToHex, parseProvenance, parseToOklch, provenanceComment, reanchorFactors, resolveShades, seedFingerprint, selectTokenSections, simulateCVD, snapShade, stableStringify, withJsonProvenance };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_NEUTRAL_COLOR,
|
|
3
|
+
DEFAULT_SEED_SHADE,
|
|
4
|
+
GENERATOR_NAME,
|
|
5
|
+
SECTIONED_FORMATS,
|
|
6
|
+
SHADE_PRESETS,
|
|
7
|
+
TAILWIND_SHADES,
|
|
8
|
+
TOKEN_SECTIONS,
|
|
3
9
|
VALID_SHADES,
|
|
4
10
|
adjustChroma,
|
|
5
11
|
adjustLightness,
|
|
6
12
|
checkSemanticContrast,
|
|
7
13
|
checkSemanticContrastAPCA,
|
|
14
|
+
chromaShadeFor,
|
|
8
15
|
classifyAPCALevel,
|
|
9
16
|
computeAccessibilityScore,
|
|
10
17
|
exportToCss,
|
|
@@ -13,6 +20,7 @@ import {
|
|
|
13
20
|
exportToTailwindV4,
|
|
14
21
|
exportTokens,
|
|
15
22
|
findContrastingColorAPCA,
|
|
23
|
+
fingerprint,
|
|
16
24
|
formatColorAs,
|
|
17
25
|
formatColorShort,
|
|
18
26
|
generateColorScale,
|
|
@@ -30,16 +38,32 @@ import {
|
|
|
30
38
|
meetsWCAG_AA,
|
|
31
39
|
meetsWCAG_AAA,
|
|
32
40
|
oklchToHex,
|
|
41
|
+
parseProvenance,
|
|
33
42
|
parseToOklch,
|
|
34
|
-
|
|
35
|
-
|
|
43
|
+
provenanceComment,
|
|
44
|
+
reanchorFactors,
|
|
45
|
+
resolveShades,
|
|
46
|
+
seedFingerprint,
|
|
47
|
+
selectTokenSections,
|
|
48
|
+
simulateCVD,
|
|
49
|
+
snapShade,
|
|
50
|
+
stableStringify,
|
|
51
|
+
withJsonProvenance
|
|
52
|
+
} from "./chunk-3OG7U5V2.js";
|
|
36
53
|
export {
|
|
37
54
|
DEFAULT_NEUTRAL_COLOR,
|
|
55
|
+
DEFAULT_SEED_SHADE,
|
|
56
|
+
GENERATOR_NAME,
|
|
57
|
+
SECTIONED_FORMATS,
|
|
58
|
+
SHADE_PRESETS,
|
|
59
|
+
TAILWIND_SHADES,
|
|
60
|
+
TOKEN_SECTIONS,
|
|
38
61
|
VALID_SHADES,
|
|
39
62
|
adjustChroma,
|
|
40
63
|
adjustLightness,
|
|
41
64
|
checkSemanticContrast,
|
|
42
65
|
checkSemanticContrastAPCA,
|
|
66
|
+
chromaShadeFor,
|
|
43
67
|
classifyAPCALevel,
|
|
44
68
|
computeAccessibilityScore,
|
|
45
69
|
exportToCss,
|
|
@@ -48,6 +72,7 @@ export {
|
|
|
48
72
|
exportToTailwindV4,
|
|
49
73
|
exportTokens,
|
|
50
74
|
findContrastingColorAPCA,
|
|
75
|
+
fingerprint,
|
|
51
76
|
formatColorAs,
|
|
52
77
|
formatColorShort,
|
|
53
78
|
generateColorScale,
|
|
@@ -65,6 +90,15 @@ export {
|
|
|
65
90
|
meetsWCAG_AA,
|
|
66
91
|
meetsWCAG_AAA,
|
|
67
92
|
oklchToHex,
|
|
93
|
+
parseProvenance,
|
|
68
94
|
parseToOklch,
|
|
69
|
-
|
|
95
|
+
provenanceComment,
|
|
96
|
+
reanchorFactors,
|
|
97
|
+
resolveShades,
|
|
98
|
+
seedFingerprint,
|
|
99
|
+
selectTokenSections,
|
|
100
|
+
simulateCVD,
|
|
101
|
+
snapShade,
|
|
102
|
+
stableStringify,
|
|
103
|
+
withJsonProvenance
|
|
70
104
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@designtools/tokens",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Headless colour token generation from brand colours: OKLCH primitive scales, contrast-checked semantic intents, light/dark modes, and serialisers for CSS custom properties (lead), Tailwind v4 (@theme static) and v3, and DTCG. Pure TypeScript, deterministic.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "CC-BY-NC-4.0",
|