@echelon-foundry/design-system 0.8.0 → 0.9.0-main.252.1
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/CHANGELOG.md +15 -0
- package/contracts/color-contract.json +1814 -0
- package/dist/all.css +82 -2
- package/dist/brands/echelon.css +16 -0
- package/dist/brands/example-harbor.css +16 -0
- package/dist/build-metrics.json +5 -5
- package/dist/components.css +5 -1
- package/dist/foundations.css +1 -1
- package/dist/icons/registry.json +1 -1
- package/dist/marketing/forma-all.css +83 -3
- package/dist/marketing/forma-echelon-marketing.css +78 -2
- package/dist/marketing/forma-marketing-theme-echelon.css +1 -1
- package/dist/marketing/forma-marketing.css +78 -2
- package/dist/marketing/forma-marketing.manifest.json +9 -9
- package/dist/marketing/forma-marketing.sha256 +4 -4
- package/dist/tokens.css +76 -0
- package/docs/BRANDING.md +6 -3
- package/docs/COLOR.md +77 -0
- package/package.json +13 -3
- package/schemas/brand-manifest.schema.json +1 -1
- package/tokens/echelon.tokens.json +252 -0
- package/tools/color-contract/build.mjs +16 -0
- package/tools/color-contract/cli.mjs +26 -0
- package/tools/color-contract/index.mjs +170 -0
|
@@ -1578,6 +1578,20 @@
|
|
|
1578
1578
|
"$value": "{primitive.color.verdigris}"
|
|
1579
1579
|
}
|
|
1580
1580
|
},
|
|
1581
|
+
"status": {
|
|
1582
|
+
"success": {
|
|
1583
|
+
"$value": "{primitive.color.status-success}"
|
|
1584
|
+
},
|
|
1585
|
+
"warning": {
|
|
1586
|
+
"$value": "{primitive.color.status-warning}"
|
|
1587
|
+
},
|
|
1588
|
+
"danger": {
|
|
1589
|
+
"$value": "{primitive.color.status-danger}"
|
|
1590
|
+
},
|
|
1591
|
+
"info": {
|
|
1592
|
+
"$value": "{primitive.color.status-info}"
|
|
1593
|
+
}
|
|
1594
|
+
},
|
|
1581
1595
|
"border": {
|
|
1582
1596
|
"subtle": {
|
|
1583
1597
|
"$value": "{primitive.color.stone}"
|
|
@@ -1648,6 +1662,20 @@
|
|
|
1648
1662
|
"$value": "{primitive.color.verdigris-light}"
|
|
1649
1663
|
}
|
|
1650
1664
|
},
|
|
1665
|
+
"status": {
|
|
1666
|
+
"success": {
|
|
1667
|
+
"$value": "{primitive.color.status-success-light}"
|
|
1668
|
+
},
|
|
1669
|
+
"warning": {
|
|
1670
|
+
"$value": "{primitive.color.status-warning-light}"
|
|
1671
|
+
},
|
|
1672
|
+
"danger": {
|
|
1673
|
+
"$value": "{primitive.color.status-danger-light}"
|
|
1674
|
+
},
|
|
1675
|
+
"info": {
|
|
1676
|
+
"$value": "{primitive.color.status-info-light}"
|
|
1677
|
+
}
|
|
1678
|
+
},
|
|
1651
1679
|
"border": {
|
|
1652
1680
|
"subtle": {
|
|
1653
1681
|
"$value": "{primitive.color.forged-iron}"
|
|
@@ -1718,6 +1746,20 @@
|
|
|
1718
1746
|
"$value": "{primitive.color.neutral-800}"
|
|
1719
1747
|
}
|
|
1720
1748
|
},
|
|
1749
|
+
"status": {
|
|
1750
|
+
"success": {
|
|
1751
|
+
"$value": "{primitive.color.status-success}"
|
|
1752
|
+
},
|
|
1753
|
+
"warning": {
|
|
1754
|
+
"$value": "{primitive.color.status-warning}"
|
|
1755
|
+
},
|
|
1756
|
+
"danger": {
|
|
1757
|
+
"$value": "{primitive.color.status-danger}"
|
|
1758
|
+
},
|
|
1759
|
+
"info": {
|
|
1760
|
+
"$value": "{primitive.color.status-info}"
|
|
1761
|
+
}
|
|
1762
|
+
},
|
|
1721
1763
|
"border": {
|
|
1722
1764
|
"subtle": {
|
|
1723
1765
|
"$value": "{primitive.color.neutral-200}"
|
|
@@ -1788,6 +1830,20 @@
|
|
|
1788
1830
|
"$value": "{primitive.color.muted-teal}"
|
|
1789
1831
|
}
|
|
1790
1832
|
},
|
|
1833
|
+
"status": {
|
|
1834
|
+
"success": {
|
|
1835
|
+
"$value": "{primitive.color.status-success}"
|
|
1836
|
+
},
|
|
1837
|
+
"warning": {
|
|
1838
|
+
"$value": "{primitive.color.status-warning}"
|
|
1839
|
+
},
|
|
1840
|
+
"danger": {
|
|
1841
|
+
"$value": "{primitive.color.status-danger}"
|
|
1842
|
+
},
|
|
1843
|
+
"info": {
|
|
1844
|
+
"$value": "{primitive.color.status-info}"
|
|
1845
|
+
}
|
|
1846
|
+
},
|
|
1791
1847
|
"border": {
|
|
1792
1848
|
"subtle": {
|
|
1793
1849
|
"$value": "{primitive.color.neutral-200}"
|
|
@@ -1858,6 +1914,20 @@
|
|
|
1858
1914
|
"$value": "{primitive.color.signal-cyan}"
|
|
1859
1915
|
}
|
|
1860
1916
|
},
|
|
1917
|
+
"status": {
|
|
1918
|
+
"success": {
|
|
1919
|
+
"$value": "{primitive.color.status-success}"
|
|
1920
|
+
},
|
|
1921
|
+
"warning": {
|
|
1922
|
+
"$value": "{primitive.color.status-warning}"
|
|
1923
|
+
},
|
|
1924
|
+
"danger": {
|
|
1925
|
+
"$value": "{primitive.color.status-danger}"
|
|
1926
|
+
},
|
|
1927
|
+
"info": {
|
|
1928
|
+
"$value": "{primitive.color.status-info}"
|
|
1929
|
+
}
|
|
1930
|
+
},
|
|
1861
1931
|
"border": {
|
|
1862
1932
|
"subtle": {
|
|
1863
1933
|
"$value": "{primitive.color.neutral-200}"
|
|
@@ -1928,6 +1998,20 @@
|
|
|
1928
1998
|
"$value": "{primitive.color.ops-blue}"
|
|
1929
1999
|
}
|
|
1930
2000
|
},
|
|
2001
|
+
"status": {
|
|
2002
|
+
"success": {
|
|
2003
|
+
"$value": "{primitive.color.status-success}"
|
|
2004
|
+
},
|
|
2005
|
+
"warning": {
|
|
2006
|
+
"$value": "{primitive.color.status-warning}"
|
|
2007
|
+
},
|
|
2008
|
+
"danger": {
|
|
2009
|
+
"$value": "{primitive.color.status-danger}"
|
|
2010
|
+
},
|
|
2011
|
+
"info": {
|
|
2012
|
+
"$value": "{primitive.color.status-info}"
|
|
2013
|
+
}
|
|
2014
|
+
},
|
|
1931
2015
|
"border": {
|
|
1932
2016
|
"subtle": {
|
|
1933
2017
|
"$value": "{primitive.color.neutral-200}"
|
|
@@ -1998,6 +2082,20 @@
|
|
|
1998
2082
|
"$value": "{primitive.color.forest}"
|
|
1999
2083
|
}
|
|
2000
2084
|
},
|
|
2085
|
+
"status": {
|
|
2086
|
+
"success": {
|
|
2087
|
+
"$value": "{primitive.color.status-success}"
|
|
2088
|
+
},
|
|
2089
|
+
"warning": {
|
|
2090
|
+
"$value": "{primitive.color.status-warning}"
|
|
2091
|
+
},
|
|
2092
|
+
"danger": {
|
|
2093
|
+
"$value": "{primitive.color.status-danger}"
|
|
2094
|
+
},
|
|
2095
|
+
"info": {
|
|
2096
|
+
"$value": "{primitive.color.status-info}"
|
|
2097
|
+
}
|
|
2098
|
+
},
|
|
2001
2099
|
"border": {
|
|
2002
2100
|
"subtle": {
|
|
2003
2101
|
"$value": "{primitive.color.paper-muted}"
|
|
@@ -2068,6 +2166,20 @@
|
|
|
2068
2166
|
"$value": "{primitive.color.signal-cyan}"
|
|
2069
2167
|
}
|
|
2070
2168
|
},
|
|
2169
|
+
"status": {
|
|
2170
|
+
"success": {
|
|
2171
|
+
"$value": "{primitive.color.status-success}"
|
|
2172
|
+
},
|
|
2173
|
+
"warning": {
|
|
2174
|
+
"$value": "{primitive.color.status-warning}"
|
|
2175
|
+
},
|
|
2176
|
+
"danger": {
|
|
2177
|
+
"$value": "{primitive.color.status-danger}"
|
|
2178
|
+
},
|
|
2179
|
+
"info": {
|
|
2180
|
+
"$value": "{primitive.color.status-info}"
|
|
2181
|
+
}
|
|
2182
|
+
},
|
|
2071
2183
|
"border": {
|
|
2072
2184
|
"subtle": {
|
|
2073
2185
|
"$value": "{primitive.color.clinical-secondary}"
|
|
@@ -2138,6 +2250,20 @@
|
|
|
2138
2250
|
"$value": "{primitive.color.verdigris-light}"
|
|
2139
2251
|
}
|
|
2140
2252
|
},
|
|
2253
|
+
"status": {
|
|
2254
|
+
"success": {
|
|
2255
|
+
"$value": "{primitive.color.status-success-light}"
|
|
2256
|
+
},
|
|
2257
|
+
"warning": {
|
|
2258
|
+
"$value": "{primitive.color.status-warning-light}"
|
|
2259
|
+
},
|
|
2260
|
+
"danger": {
|
|
2261
|
+
"$value": "{primitive.color.status-danger-light}"
|
|
2262
|
+
},
|
|
2263
|
+
"info": {
|
|
2264
|
+
"$value": "{primitive.color.status-info-light}"
|
|
2265
|
+
}
|
|
2266
|
+
},
|
|
2141
2267
|
"border": {
|
|
2142
2268
|
"subtle": {
|
|
2143
2269
|
"$value": "{primitive.color.forged-iron}"
|
|
@@ -2208,6 +2334,20 @@
|
|
|
2208
2334
|
"$value": "{primitive.color.comp-rust}"
|
|
2209
2335
|
}
|
|
2210
2336
|
},
|
|
2337
|
+
"status": {
|
|
2338
|
+
"success": {
|
|
2339
|
+
"$value": "{primitive.color.status-success}"
|
|
2340
|
+
},
|
|
2341
|
+
"warning": {
|
|
2342
|
+
"$value": "{primitive.color.status-warning}"
|
|
2343
|
+
},
|
|
2344
|
+
"danger": {
|
|
2345
|
+
"$value": "{primitive.color.status-danger}"
|
|
2346
|
+
},
|
|
2347
|
+
"info": {
|
|
2348
|
+
"$value": "{primitive.color.status-info}"
|
|
2349
|
+
}
|
|
2350
|
+
},
|
|
2211
2351
|
"border": {
|
|
2212
2352
|
"subtle": {
|
|
2213
2353
|
"$value": "{primitive.color.neutral-200}"
|
|
@@ -2278,6 +2418,20 @@
|
|
|
2278
2418
|
"$value": "{primitive.color.analog-teal}"
|
|
2279
2419
|
}
|
|
2280
2420
|
},
|
|
2421
|
+
"status": {
|
|
2422
|
+
"success": {
|
|
2423
|
+
"$value": "{primitive.color.status-success}"
|
|
2424
|
+
},
|
|
2425
|
+
"warning": {
|
|
2426
|
+
"$value": "{primitive.color.status-warning}"
|
|
2427
|
+
},
|
|
2428
|
+
"danger": {
|
|
2429
|
+
"$value": "{primitive.color.status-danger}"
|
|
2430
|
+
},
|
|
2431
|
+
"info": {
|
|
2432
|
+
"$value": "{primitive.color.status-info}"
|
|
2433
|
+
}
|
|
2434
|
+
},
|
|
2281
2435
|
"border": {
|
|
2282
2436
|
"subtle": {
|
|
2283
2437
|
"$value": "{primitive.color.neutral-200}"
|
|
@@ -2348,6 +2502,20 @@
|
|
|
2348
2502
|
"$value": "{primitive.color.split-rust}"
|
|
2349
2503
|
}
|
|
2350
2504
|
},
|
|
2505
|
+
"status": {
|
|
2506
|
+
"success": {
|
|
2507
|
+
"$value": "{primitive.color.status-success}"
|
|
2508
|
+
},
|
|
2509
|
+
"warning": {
|
|
2510
|
+
"$value": "{primitive.color.status-warning}"
|
|
2511
|
+
},
|
|
2512
|
+
"danger": {
|
|
2513
|
+
"$value": "{primitive.color.status-danger}"
|
|
2514
|
+
},
|
|
2515
|
+
"info": {
|
|
2516
|
+
"$value": "{primitive.color.status-info}"
|
|
2517
|
+
}
|
|
2518
|
+
},
|
|
2351
2519
|
"border": {
|
|
2352
2520
|
"subtle": {
|
|
2353
2521
|
"$value": "{primitive.color.neutral-200}"
|
|
@@ -2418,6 +2586,20 @@
|
|
|
2418
2586
|
"$value": "{primitive.color.neutral-650}"
|
|
2419
2587
|
}
|
|
2420
2588
|
},
|
|
2589
|
+
"status": {
|
|
2590
|
+
"success": {
|
|
2591
|
+
"$value": "{primitive.color.status-success}"
|
|
2592
|
+
},
|
|
2593
|
+
"warning": {
|
|
2594
|
+
"$value": "{primitive.color.status-warning}"
|
|
2595
|
+
},
|
|
2596
|
+
"danger": {
|
|
2597
|
+
"$value": "{primitive.color.status-danger}"
|
|
2598
|
+
},
|
|
2599
|
+
"info": {
|
|
2600
|
+
"$value": "{primitive.color.status-info}"
|
|
2601
|
+
}
|
|
2602
|
+
},
|
|
2421
2603
|
"border": {
|
|
2422
2604
|
"subtle": {
|
|
2423
2605
|
"$value": "{primitive.color.neutral-200}"
|
|
@@ -2488,6 +2670,20 @@
|
|
|
2488
2670
|
"$value": "{primitive.color.muted-teal}"
|
|
2489
2671
|
}
|
|
2490
2672
|
},
|
|
2673
|
+
"status": {
|
|
2674
|
+
"success": {
|
|
2675
|
+
"$value": "{primitive.color.status-success}"
|
|
2676
|
+
},
|
|
2677
|
+
"warning": {
|
|
2678
|
+
"$value": "{primitive.color.status-warning}"
|
|
2679
|
+
},
|
|
2680
|
+
"danger": {
|
|
2681
|
+
"$value": "{primitive.color.status-danger}"
|
|
2682
|
+
},
|
|
2683
|
+
"info": {
|
|
2684
|
+
"$value": "{primitive.color.status-info}"
|
|
2685
|
+
}
|
|
2686
|
+
},
|
|
2491
2687
|
"border": {
|
|
2492
2688
|
"subtle": {
|
|
2493
2689
|
"$value": "{primitive.color.editorial-surface}"
|
|
@@ -2558,6 +2754,20 @@
|
|
|
2558
2754
|
"$value": "{primitive.color.earth-green}"
|
|
2559
2755
|
}
|
|
2560
2756
|
},
|
|
2757
|
+
"status": {
|
|
2758
|
+
"success": {
|
|
2759
|
+
"$value": "{primitive.color.status-success}"
|
|
2760
|
+
},
|
|
2761
|
+
"warning": {
|
|
2762
|
+
"$value": "{primitive.color.status-warning}"
|
|
2763
|
+
},
|
|
2764
|
+
"danger": {
|
|
2765
|
+
"$value": "{primitive.color.status-danger}"
|
|
2766
|
+
},
|
|
2767
|
+
"info": {
|
|
2768
|
+
"$value": "{primitive.color.status-info}"
|
|
2769
|
+
}
|
|
2770
|
+
},
|
|
2561
2771
|
"border": {
|
|
2562
2772
|
"subtle": {
|
|
2563
2773
|
"$value": "{primitive.color.earth-surface}"
|
|
@@ -2628,6 +2838,20 @@
|
|
|
2628
2838
|
"$value": "{primitive.color.signal-cyan}"
|
|
2629
2839
|
}
|
|
2630
2840
|
},
|
|
2841
|
+
"status": {
|
|
2842
|
+
"success": {
|
|
2843
|
+
"$value": "{primitive.color.status-success}"
|
|
2844
|
+
},
|
|
2845
|
+
"warning": {
|
|
2846
|
+
"$value": "{primitive.color.status-warning}"
|
|
2847
|
+
},
|
|
2848
|
+
"danger": {
|
|
2849
|
+
"$value": "{primitive.color.status-danger}"
|
|
2850
|
+
},
|
|
2851
|
+
"info": {
|
|
2852
|
+
"$value": "{primitive.color.status-info}"
|
|
2853
|
+
}
|
|
2854
|
+
},
|
|
2631
2855
|
"border": {
|
|
2632
2856
|
"subtle": {
|
|
2633
2857
|
"$value": "{primitive.color.institutional-surface}"
|
|
@@ -2698,6 +2922,20 @@
|
|
|
2698
2922
|
"$value": "{primitive.color.nature-blue}"
|
|
2699
2923
|
}
|
|
2700
2924
|
},
|
|
2925
|
+
"status": {
|
|
2926
|
+
"success": {
|
|
2927
|
+
"$value": "{primitive.color.status-success}"
|
|
2928
|
+
},
|
|
2929
|
+
"warning": {
|
|
2930
|
+
"$value": "{primitive.color.status-warning}"
|
|
2931
|
+
},
|
|
2932
|
+
"danger": {
|
|
2933
|
+
"$value": "{primitive.color.status-danger}"
|
|
2934
|
+
},
|
|
2935
|
+
"info": {
|
|
2936
|
+
"$value": "{primitive.color.status-info}"
|
|
2937
|
+
}
|
|
2938
|
+
},
|
|
2701
2939
|
"border": {
|
|
2702
2940
|
"subtle": {
|
|
2703
2941
|
"$value": "{primitive.color.nature-surface}"
|
|
@@ -2768,6 +3006,20 @@
|
|
|
2768
3006
|
"$value": "{primitive.color.tech-amber}"
|
|
2769
3007
|
}
|
|
2770
3008
|
},
|
|
3009
|
+
"status": {
|
|
3010
|
+
"success": {
|
|
3011
|
+
"$value": "{primitive.color.status-success-light}"
|
|
3012
|
+
},
|
|
3013
|
+
"warning": {
|
|
3014
|
+
"$value": "{primitive.color.status-warning-light}"
|
|
3015
|
+
},
|
|
3016
|
+
"danger": {
|
|
3017
|
+
"$value": "{primitive.color.status-danger-light}"
|
|
3018
|
+
},
|
|
3019
|
+
"info": {
|
|
3020
|
+
"$value": "{primitive.color.status-info-light}"
|
|
3021
|
+
}
|
|
3022
|
+
},
|
|
2771
3023
|
"border": {
|
|
2772
3024
|
"subtle": {
|
|
2773
3025
|
"$value": "{primitive.color.forged-iron}"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { createColorContract } from "./index.mjs";
|
|
5
|
+
|
|
6
|
+
const root = process.cwd();
|
|
7
|
+
const read = file => JSON.parse(fs.readFileSync(path.join(root, file), "utf8"));
|
|
8
|
+
const brandFiles = fs.readdirSync(path.join(root, "brands")).filter(file => file.endsWith(".brand.json")).sort();
|
|
9
|
+
const contract = createColorContract({
|
|
10
|
+
tokenDocument: read("tokens/echelon.tokens.json"),
|
|
11
|
+
brands: brandFiles.map(file => ({ file: `brands/${file}`, document: read(`brands/${file}`) })),
|
|
12
|
+
formaVersion: read("package.json").version
|
|
13
|
+
});
|
|
14
|
+
const output = path.join(root, "contracts/color-contract.json");
|
|
15
|
+
fs.writeFileSync(output, JSON.stringify(contract, null, 2) + "\n");
|
|
16
|
+
console.log(`color contract passed: ${contract.publicTokens.length} public tokens, ${contract.contexts.length} theme/brand contexts -> ${path.relative(root, output)}`);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { loadColorContract, validateColorFiles } from "./index.mjs";
|
|
3
|
+
|
|
4
|
+
const args = process.argv.slice(2);
|
|
5
|
+
const usage = () => {
|
|
6
|
+
console.error("usage: forma-color validate [--contract FILE] FILE...");
|
|
7
|
+
process.exitCode = 2;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
if (args.shift() !== "validate") usage();
|
|
11
|
+
else {
|
|
12
|
+
let contractPath;
|
|
13
|
+
const marker = args.indexOf("--contract");
|
|
14
|
+
if (marker >= 0) {
|
|
15
|
+
contractPath = args[marker + 1];
|
|
16
|
+
if (!contractPath) usage();
|
|
17
|
+
args.splice(marker, 2);
|
|
18
|
+
}
|
|
19
|
+
if (!args.length) usage();
|
|
20
|
+
else {
|
|
21
|
+
const findings = validateColorFiles(args, { contract: loadColorContract(contractPath) });
|
|
22
|
+
for (const finding of findings) console.error(`${finding.file}:${finding.line}:${finding.column} ${finding.code} ${finding.message}`);
|
|
23
|
+
if (findings.length) process.exitCode = 1;
|
|
24
|
+
else console.log(`${args.length} file(s): valid Forma color references`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
export const COLOR_CONTRACT_FORMAT = "forma.color-contract/1.0.0";
|
|
6
|
+
|
|
7
|
+
const walkLeaves = (value, prefix = [], output = []) => {
|
|
8
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return output;
|
|
9
|
+
if (Object.hasOwn(value, "$value")) output.push([prefix.join("."), value]);
|
|
10
|
+
else for (const [key, child] of Object.entries(value)) {
|
|
11
|
+
if (!key.startsWith("$")) walkLeaves(child, [...prefix, key], output);
|
|
12
|
+
}
|
|
13
|
+
return output;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const atPath = (root, dotted) => dotted.split(".").reduce((value, key) => value?.[key], root);
|
|
17
|
+
|
|
18
|
+
const resolveDtcg = (root, token, stack = []) => {
|
|
19
|
+
const value = token?.$value ?? token;
|
|
20
|
+
if (typeof value === "string" && /^\{[^}]+\}$/.test(value)) {
|
|
21
|
+
const alias = value.slice(1, -1);
|
|
22
|
+
if (stack.includes(alias)) throw new Error(`circular color alias ${[...stack, alias].join(" -> ")}`);
|
|
23
|
+
const target = atPath(root, alias);
|
|
24
|
+
if (!target) throw new Error(`unknown color alias ${value}`);
|
|
25
|
+
return resolveDtcg(root, target, [...stack, alias]);
|
|
26
|
+
}
|
|
27
|
+
const hex = value?.hex ?? value;
|
|
28
|
+
if (typeof hex !== "string" || !/^#[0-9a-f]{6}$/i.test(hex)) throw new Error(`color token does not resolve to six-digit hex: ${JSON.stringify(value)}`);
|
|
29
|
+
return hex.toLowerCase();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const flattenTheme = (document, theme) => Object.fromEntries(
|
|
33
|
+
walkLeaves(document.semantic?.[theme]?.color).map(([role, token]) => [`--ef-color-${role.replaceAll(".", "-")}`, resolveDtcg(document, token)])
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const flattenBrandTheme = theme => {
|
|
37
|
+
const output = {};
|
|
38
|
+
const visit = (value, prefix = []) => {
|
|
39
|
+
for (const [key, child] of Object.entries(value ?? {})) {
|
|
40
|
+
if (typeof child === "string") output[`--ef-color-${[...prefix, key].join("-")}`] = child.toLowerCase();
|
|
41
|
+
else visit(child, [...prefix, key]);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
visit(theme?.color);
|
|
45
|
+
return output;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const rolePairings = [
|
|
49
|
+
{ role: "primary-action", classification: "supported-primitive", foreground: "--ef-color-text-inverse", background: "--ef-color-surface-inverse", minimumContrast: 4.5, nonColorCue: "visible action label and native button semantics" },
|
|
50
|
+
{ role: "secondary-action", classification: "supported-primitive", foreground: "--ef-color-text-primary", background: "--ef-color-surface-primary", boundary: "--ef-color-border-functional", minimumContrast: 4.5, nonColorCue: "visible action label and functional border" },
|
|
51
|
+
{ role: "link", classification: "supported-primitive", foreground: "--ef-color-accent-primary", background: "--ef-color-surface-primary", minimumContrast: 4.5, nonColorCue: "underline or link context; secondary surfaces re-pair through Forma's surface hook" },
|
|
52
|
+
{ role: "selection", classification: "supported-primitive", foreground: "--ef-color-text-inverse", background: "--ef-color-surface-inverse", minimumContrast: 4.5, nonColorCue: "native selected, checked, or aria-current state" },
|
|
53
|
+
...[["notice", "info"], ["pending-or-unknown", "info"], ["warning", "warning"], ["danger", "danger"], ["success", "success"]].map(([role, token]) => ({ role, classification: "supported-primitive", foreground: `--ef-color-status-${token}`, background: "--ef-color-surface-primary", minimumContrast: 4.5, nonColorCue: "state text plus glyph, border, or accessible name" })),
|
|
54
|
+
{ role: "disabled", classification: "supported-primitive", foreground: "--ef-color-text-primary", background: "--ef-color-surface-secondary", boundary: "--ef-color-border-functional", minimumContrast: 4.5, nonColorCue: "native disabled state, dashed boundary, and not-allowed cursor; opacity is supplemental" },
|
|
55
|
+
{ role: "focus", classification: "supported-primitive", foreground: "--ef-color-focus-ring", background: "--ef-color-surface-primary", minimumContrast: 3, nonColorCue: "two-part outline geometry shown by keyboard focus" },
|
|
56
|
+
{ role: "categorical-data-visualization", classification: "application-extension", minimumContrast: 3, nonColorCue: "direct labels, shapes, patterns, or a text/table alternative", note: "Forma does not certify a universal categorical palette." },
|
|
57
|
+
{ role: "ordinal-data-visualization", classification: "application-extension", minimumContrast: 3, nonColorCue: "ordered position plus labels, patterns, or a text/table alternative", note: "Applications must validate the complete rendered scale in context." }
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
export const createColorContract = ({ tokenDocument, brands, formaVersion }) => {
|
|
61
|
+
const themeIds = Object.keys(tokenDocument.semantic ?? {});
|
|
62
|
+
const themes = themeIds.map(id => ({
|
|
63
|
+
kind: "theme",
|
|
64
|
+
id,
|
|
65
|
+
selector: id === "light" ? ":root, [data-ef-theme=\"light\"]" : `[data-ef-theme=\"${id}\"]`,
|
|
66
|
+
source: "tokens/echelon.tokens.json",
|
|
67
|
+
values: flattenTheme(tokenDocument, id)
|
|
68
|
+
}));
|
|
69
|
+
const baseline = themes.find(context => context.id === "light")?.values ?? {};
|
|
70
|
+
const publicNames = Object.keys(baseline).sort();
|
|
71
|
+
const rolesByName = new Map(walkLeaves(tokenDocument.semantic.light.color).map(([role]) => [`--ef-color-${role.replaceAll(".", "-")}`, role]));
|
|
72
|
+
for (const context of themes) {
|
|
73
|
+
const missing = publicNames.filter(name => !context.values[name]);
|
|
74
|
+
if (missing.length) throw new Error(`theme ${context.id} omits public colors: ${missing.join(", ")}`);
|
|
75
|
+
}
|
|
76
|
+
const brandContexts = brands.flatMap(({ file, document }) => ["light", "dark"].map(theme => {
|
|
77
|
+
const values = { ...flattenTheme(tokenDocument, theme), ...flattenBrandTheme(document.themes?.[theme]) };
|
|
78
|
+
const missing = publicNames.filter(name => !values[name]);
|
|
79
|
+
if (missing.length) throw new Error(`brand ${document.id}/${theme} omits public colors: ${missing.join(", ")}`);
|
|
80
|
+
return { kind: "brand", id: `${document.id}/${theme}`, selector: `[data-ef-brand=\"${document.id}\"][data-ef-theme=\"${theme}\"]`, source: file, values };
|
|
81
|
+
}));
|
|
82
|
+
return {
|
|
83
|
+
format: COLOR_CONTRACT_FORMAT,
|
|
84
|
+
formaVersion,
|
|
85
|
+
validationScope: "CSS var() references to --ef-color-* plus reserved internal color-related prefixes; other Forma APIs are governed by their own contracts.",
|
|
86
|
+
compatibility: { policy: "Validate with the contract shipped by the pinned Forma package version.", additiveWithinMajor: true },
|
|
87
|
+
fallbackPolicy: {
|
|
88
|
+
unknownFormaToken: "refused-even-with-fallback",
|
|
89
|
+
applicationToken: "ignored",
|
|
90
|
+
knownFormaTokenLiteralFallback: "permitted-only-when-the-six-digit-hex-equals-the-light-theme-value",
|
|
91
|
+
rationale: "A literal may support standalone layer loading, but it must not invent a color or make an unsupported Forma name appear valid."
|
|
92
|
+
},
|
|
93
|
+
publicTokens: publicNames.map(name => ({
|
|
94
|
+
name,
|
|
95
|
+
role: rolesByName.get(name),
|
|
96
|
+
scopes: ["root", "theme", "brand", "skin"],
|
|
97
|
+
variants: { themes: themeIds, brands: brands.map(item => item.document.id) },
|
|
98
|
+
source: { file: "tokens/echelon.tokens.json", path: `semantic.<theme>.color.${rolesByName.get(name)}` },
|
|
99
|
+
provenance: { kind: "generated", compiler: "tools/color-contract/build.mjs" },
|
|
100
|
+
deprecatedAliases: []
|
|
101
|
+
})),
|
|
102
|
+
internalVariables: {
|
|
103
|
+
public: false,
|
|
104
|
+
prefixes: ["--ef-tone-", "--ef-surface-", "--ef-field-", "--ef-grid-", "--ef-effect-"],
|
|
105
|
+
policy: "Implementation variables are not a consumer compatibility contract."
|
|
106
|
+
},
|
|
107
|
+
unsupportedNames: [
|
|
108
|
+
{ name: "--ef-color-action-primary", use: "--ef-color-surface-inverse", pairWith: "--ef-color-text-inverse" },
|
|
109
|
+
{ name: "--ef-color-text-link", use: "--ef-color-accent-primary", pairWith: "--ef-color-surface-primary" },
|
|
110
|
+
{ name: "--ef-color-focus", use: "--ef-color-focus-ring", pairWith: "--ef-color-focus-gap" },
|
|
111
|
+
{ name: "--ef-color-text-danger", use: "--ef-color-status-danger", pairWith: "--ef-color-surface-primary" }
|
|
112
|
+
],
|
|
113
|
+
rolePairings,
|
|
114
|
+
forcedColors: { foreground: "CanvasText", surface: "Canvas", selection: "Highlight/HighlightText", authorAdjust: "auto" },
|
|
115
|
+
contexts: [...themes, ...brandContexts]
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const defaultContractPath = fileURLToPath(new URL("../../contracts/color-contract.json", import.meta.url));
|
|
120
|
+
export const loadColorContract = (contractPath = defaultContractPath) => JSON.parse(fs.readFileSync(contractPath, "utf8"));
|
|
121
|
+
|
|
122
|
+
const editDistance = (left, right) => {
|
|
123
|
+
const row = [...Array(right.length + 1).keys()];
|
|
124
|
+
for (let i = 1; i <= left.length; i += 1) {
|
|
125
|
+
let previous = row[0]; row[0] = i;
|
|
126
|
+
for (let j = 1; j <= right.length; j += 1) {
|
|
127
|
+
const saved = row[j];
|
|
128
|
+
row[j] = Math.min(row[j] + 1, row[j - 1] + 1, previous + (left[i - 1] === right[j - 1] ? 0 : 1));
|
|
129
|
+
previous = saved;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return row[right.length];
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const location = (source, index) => {
|
|
136
|
+
const before = source.slice(0, index);
|
|
137
|
+
const lines = before.split("\n");
|
|
138
|
+
return { line: lines.length, column: lines.at(-1).length + 1 };
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const validateCssColorReferences = (source, { contract = loadColorContract(), file = "<input>" } = {}) => {
|
|
142
|
+
const known = new Set(contract.publicTokens.map(token => token.name));
|
|
143
|
+
const replacements = new Map(contract.unsupportedNames.map(item => [item.name, item.use]));
|
|
144
|
+
const internalPrefixes = contract.internalVariables?.prefixes ?? [];
|
|
145
|
+
const defaults = contract.contexts.find(item => item.kind === "theme" && item.id === "light")?.values ?? {};
|
|
146
|
+
const findings = [];
|
|
147
|
+
const pattern = /var\(\s*(--[a-z0-9_-]+)/gi;
|
|
148
|
+
for (const match of source.matchAll(pattern)) {
|
|
149
|
+
const name = match[1];
|
|
150
|
+
if (!name.startsWith("--ef-")) continue;
|
|
151
|
+
const where = location(source, match.index + match[0].indexOf(name));
|
|
152
|
+
if (internalPrefixes.some(prefix => name.startsWith(prefix))) {
|
|
153
|
+
findings.push({ code: "COLOR_INTERNAL_FORMA_VARIABLE", file, ...where, token: name, suggestion: "use a public --ef-color-* role", message: `${name} is an internal implementation variable; use a public semantic color role` });
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (!name.startsWith("--ef-color-")) continue;
|
|
157
|
+
if (!known.has(name)) {
|
|
158
|
+
const suggestion = replacements.get(name) ?? [...known].sort((a, b) => editDistance(name, a) - editDistance(name, b) || a.localeCompare(b))[0];
|
|
159
|
+
findings.push({ code: "COLOR_UNKNOWN_FORMA_TOKEN", file, ...where, token: name, suggestion, message: `unsupported Forma token ${name}; use ${suggestion}` });
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const call = source.slice(match.index).match(/^var\(\s*--[a-z0-9_-]+\s*,\s*(#[0-9a-f]{6})\s*\)/i);
|
|
163
|
+
if (call && call[1].toLowerCase() !== defaults[name]) {
|
|
164
|
+
findings.push({ code: "COLOR_LITERAL_FALLBACK_MISMATCH", file, ...where, token: name, suggestion: defaults[name], message: `literal fallback for ${name} must equal its light-theme value ${defaults[name]} or be removed` });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return findings.sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column || a.code.localeCompare(b.code));
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export const validateColorFiles = (files, options = {}) => files.flatMap(file => validateCssColorReferences(fs.readFileSync(file, "utf8"), { ...options, file: path.normalize(file) }));
|