argot-css 0.0.0-stage → 0.0.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/LICENSE.md +20 -0
- package/README.md +259 -2
- package/bin/argot.js +4 -0
- package/dist/cli/ansiColors.d.ts +7 -0
- package/dist/cli/ansiColors.js +8 -0
- package/dist/cli/ansiColors.js.map +1 -0
- package/dist/cli/print.d.ts +2 -0
- package/dist/cli/print.js +13 -0
- package/dist/cli/print.js.map +1 -0
- package/dist/cli/run.d.ts +2 -0
- package/dist/cli/run.js +34 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/usage.d.ts +2 -0
- package/dist/cli/usage.js +17 -0
- package/dist/cli/usage.js.map +1 -0
- package/dist/palette/cli.d.ts +2 -0
- package/dist/palette/cli.js +33 -0
- package/dist/palette/cli.js.map +1 -0
- package/dist/palette/generateName.d.ts +3 -0
- package/dist/palette/generateName.js +65 -0
- package/dist/palette/generateName.js.map +1 -0
- package/dist/palette/generatePalette.d.ts +7 -0
- package/dist/palette/generatePalette.js +97 -0
- package/dist/palette/generatePalette.js.map +1 -0
- package/dist/palette/index.d.ts +5 -0
- package/dist/palette/index.js +6 -0
- package/dist/palette/index.js.map +1 -0
- package/dist/palette/node.d.ts +19 -0
- package/dist/palette/node.js +70 -0
- package/dist/palette/node.js.map +1 -0
- package/dist/palette/parseCssColor.d.ts +7 -0
- package/dist/palette/parseCssColor.js +41 -0
- package/dist/palette/parseCssColor.js.map +1 -0
- package/dist/palette/render.d.ts +8 -0
- package/dist/palette/render.js +49 -0
- package/dist/palette/render.js.map +1 -0
- package/dist/palette/types.d.ts +50 -0
- package/dist/palette/types.js +2 -0
- package/dist/palette/types.js.map +1 -0
- package/dist/palette/validation.d.ts +13 -0
- package/dist/palette/validation.js +110 -0
- package/dist/palette/validation.js.map +1 -0
- package/dist/processor/atImport.d.ts +4 -0
- package/dist/processor/atImport.js +149 -0
- package/dist/processor/atImport.js.map +1 -0
- package/dist/processor/cli.d.ts +1 -0
- package/dist/processor/cli.js +32 -0
- package/dist/processor/cli.js.map +1 -0
- package/dist/processor/index.d.ts +7 -0
- package/dist/processor/index.js +47 -0
- package/dist/processor/index.js.map +1 -0
- package/dist/processor/parseImportParams.d.ts +19 -0
- package/dist/processor/parseImportParams.js +139 -0
- package/dist/processor/parseImportParams.js.map +1 -0
- package/dist/processor/stylelintDefault.d.ts +4 -0
- package/dist/processor/stylelintDefault.js +19 -0
- package/dist/processor/stylelintDefault.js.map +1 -0
- package/dist/semantics/cli.d.ts +2 -0
- package/dist/semantics/cli.js +34 -0
- package/dist/semantics/cli.js.map +1 -0
- package/dist/semantics/generate.d.ts +16 -0
- package/dist/semantics/generate.js +53 -0
- package/dist/semantics/generate.js.map +1 -0
- package/dist/semantics/load-tokens.d.ts +29 -0
- package/dist/semantics/load-tokens.js +74 -0
- package/dist/semantics/load-tokens.js.map +1 -0
- package/dist/semantics/token-index.d.ts +14 -0
- package/dist/semantics/token-index.js +30 -0
- package/dist/semantics/token-index.js.map +1 -0
- package/dist/stylelint/config.d.ts +16 -0
- package/dist/stylelint/config.js +19 -0
- package/dist/stylelint/config.js.map +1 -0
- package/dist/stylelint/index.d.ts +3 -0
- package/dist/stylelint/index.js +4 -0
- package/dist/stylelint/index.js.map +1 -0
- package/dist/stylelint/rules/valid-token.d.ts +3 -0
- package/dist/stylelint/rules/valid-token.js +32 -0
- package/dist/stylelint/rules/valid-token.js.map +1 -0
- package/docs/api.md +514 -0
- package/package.json +115 -4
- package/templates/base.css +53 -0
- package/templates/modules/index.css +0 -0
- package/templates/semantics-extended.css +115 -0
- package/templates/semantics.css +94 -0
- package/templates/styles.css +7 -0
- package/tokens/borders.json +37 -0
- package/tokens/color-bg.json +104 -0
- package/tokens/color-border.json +59 -0
- package/tokens/color-chart.json +40 -0
- package/tokens/color-icon.json +53 -0
- package/tokens/color-text.json +107 -0
- package/tokens/layout.json +66 -0
- package/tokens/misc.json +16 -0
- package/tokens/motion.json +40 -0
- package/tokens/spacing.json +41 -0
- package/tokens/typography.json +107 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-index.js","sourceRoot":"","sources":["../../src/semantics/token-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C;;GAEG;AACH,SAAS,aAAa,CAAC,UAAwB,EAAE,QAAQ,EAAE,IAAI,EAAE;IAC/D,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAEhC,KAAK,MAAM,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1C,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC/B,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,OAAO;QACL,KAAK;QACL,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,IAAI,EAAE;KAC/B,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAC1B,IAAY,EACZ,QAA2B;IAE3B,OAAO,QAAQ,CAAC,IAAI,CAClB,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,MAAM,GAAG,CAAC,CAC7D,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,CAAC","sourcesContent":["import { loadTokens } from './load-tokens.ts';\nimport type { TokenOptions } from './load-tokens.ts';\n\n/**\n * Build lookup data from packaged token JSON.\n */\nfunction getTokenIndex(options: TokenOptions = { extended: true }) {\n const names = new Set<string>();\n\n for (const section of loadTokens(options)) {\n for (const token of section.tokens) {\n names.add(token.name.slice(2));\n }\n }\n\n const prefixes = new Set<string>();\n for (const name of names) {\n const dash = name.indexOf('-');\n prefixes.add(dash === -1 ? name : name.slice(0, dash));\n }\n\n return {\n names,\n prefixes: [...prefixes].sort(),\n };\n}\n\n/**\n * True when a custom-property name (without leading --) sits in an Argot\n * namespace prefix (e.g. text-*, bg-*, space-*), whether or not it is known.\n */\nfunction looksLikeArgotToken(\n name: string,\n prefixes: readonly string[],\n): boolean {\n return prefixes.some(\n (prefix) => name === prefix || name.startsWith(`${prefix}-`),\n );\n}\n\nexport { getTokenIndex, looksLikeArgotToken };\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shareable Stylelint config for Argot token usage.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* // stylelint.config.js
|
|
6
|
+
* export default {
|
|
7
|
+
* extends: ['argot-css/stylelint/config'],
|
|
8
|
+
* };
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: {
|
|
11
|
+
plugins: string[];
|
|
12
|
+
rules: {
|
|
13
|
+
'argot/valid-token': boolean;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export default _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
/**
|
|
3
|
+
* Shareable Stylelint config for Argot token usage.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* // stylelint.config.js
|
|
7
|
+
* export default {
|
|
8
|
+
* extends: ['argot-css/stylelint/config'],
|
|
9
|
+
* };
|
|
10
|
+
*/
|
|
11
|
+
export default {
|
|
12
|
+
plugins: [
|
|
13
|
+
fileURLToPath(new URL(import.meta.url.endsWith('.ts') ? './index.ts' : './index.js', import.meta.url)),
|
|
14
|
+
],
|
|
15
|
+
rules: {
|
|
16
|
+
'argot/valid-token': true,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/stylelint/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC;;;;;;;;GAQG;AACH,eAAe;IACb,OAAO,EAAE;QACP,aAAa,CACX,IAAI,GAAG,CACL,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,EAC7D,MAAM,CAAC,IAAI,CAAC,GAAG,CAChB,CACF;KACF;IACD,KAAK,EAAE;QACL,mBAAmB,EAAE,IAAI;KAC1B;CACe,CAAC","sourcesContent":["import { fileURLToPath } from 'node:url';\nimport type { Config } from 'stylelint';\n\n/**\n * Shareable Stylelint config for Argot token usage.\n *\n * @example\n * // stylelint.config.js\n * export default {\n * extends: ['argot-css/stylelint/config'],\n * };\n */\nexport default {\n plugins: [\n fileURLToPath(\n new URL(\n import.meta.url.endsWith('.ts') ? './index.ts' : './index.js',\n import.meta.url,\n ),\n ),\n ],\n rules: {\n 'argot/valid-token': true,\n },\n} satisfies Config;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stylelint/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAEhD,0CAA0C;AAC1C,eAAe,CAAC,UAAU,CAAC,CAAC","sourcesContent":["import validToken from './rules/valid-token.ts';\n\n/** Stylelint plugins shipped by Argot. */\nexport default [validToken];\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import stylelint from 'stylelint';
|
|
2
|
+
const { createPlugin, utils: { ruleMessages, validateOptions }, } = stylelint;
|
|
3
|
+
const ruleName = 'argot/valid-token';
|
|
4
|
+
const messages = ruleMessages(ruleName, {
|
|
5
|
+
rejected: (prop) => `Unexpected unknown Argot token "--${prop}". Check the name against the Argot token list.`,
|
|
6
|
+
});
|
|
7
|
+
const meta = {
|
|
8
|
+
url: 'https://github.com/keithjgrant/argot/blob/main/docs/product-scope.md',
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Placeholder: consumers are expected to extend the generated template with
|
|
12
|
+
* their own custom properties. Re-enable checks here when we have rules that
|
|
13
|
+
* fit that workflow (not a closed token allowlist).
|
|
14
|
+
*
|
|
15
|
+
* Token index helpers remain in `src/semantics/token-index.ts` for future rules.
|
|
16
|
+
*/
|
|
17
|
+
const ruleFunction = (primary) => {
|
|
18
|
+
return (_root, result) => {
|
|
19
|
+
const validOptions = validateOptions(result, ruleName, {
|
|
20
|
+
actual: primary,
|
|
21
|
+
possible: [true],
|
|
22
|
+
});
|
|
23
|
+
if (!validOptions)
|
|
24
|
+
return;
|
|
25
|
+
// no-op
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
ruleFunction.ruleName = ruleName;
|
|
29
|
+
ruleFunction.messages = messages;
|
|
30
|
+
ruleFunction.meta = meta;
|
|
31
|
+
export default createPlugin(ruleName, ruleFunction);
|
|
32
|
+
//# sourceMappingURL=valid-token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valid-token.js","sourceRoot":"","sources":["../../../src/stylelint/rules/valid-token.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAGlC,MAAM,EACJ,YAAY,EACZ,KAAK,EAAE,EAAE,YAAY,EAAE,eAAe,EAAE,GACzC,GAAG,SAAS,CAAC;AAEd,MAAM,QAAQ,GAAG,mBAAmB,CAAC;AAErC,MAAM,QAAQ,GAAG,YAAY,CAAC,QAAQ,EAAE;IACtC,QAAQ,EAAE,CAAC,IAAY,EAAE,EAAE,CACzB,qCAAqC,IAAI,iDAAiD;CAC7F,CAAC,CAAC;AAEH,MAAM,IAAI,GAAG;IACX,GAAG,EAAE,sEAAsE;CAC5E,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,YAAY,GAAS,CAAC,OAAO,EAAE,EAAE;IACrC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QACvB,MAAM,YAAY,GAAG,eAAe,CAAC,MAAM,EAAE,QAAQ,EAAE;YACrD,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE,CAAC,IAAI,CAAC;SACjB,CAAC,CAAC;QAEH,IAAI,CAAC,YAAY;YAAE,OAAO;QAC1B,QAAQ;IACV,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,YAAY,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACjC,YAAY,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACjC,YAAY,CAAC,IAAI,GAAG,IAAI,CAAC;AAEzB,eAAe,YAAY,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC","sourcesContent":["import stylelint from 'stylelint';\nimport type { Rule } from 'stylelint';\n\nconst {\n createPlugin,\n utils: { ruleMessages, validateOptions },\n} = stylelint;\n\nconst ruleName = 'argot/valid-token';\n\nconst messages = ruleMessages(ruleName, {\n rejected: (prop: string) =>\n `Unexpected unknown Argot token \"--${prop}\". Check the name against the Argot token list.`,\n});\n\nconst meta = {\n url: 'https://github.com/keithjgrant/argot/blob/main/docs/product-scope.md',\n};\n\n/**\n * Placeholder: consumers are expected to extend the generated template with\n * their own custom properties. Re-enable checks here when we have rules that\n * fit that workflow (not a closed token allowlist).\n *\n * Token index helpers remain in `src/semantics/token-index.ts` for future rules.\n */\nconst ruleFunction: Rule = (primary) => {\n return (_root, result) => {\n const validOptions = validateOptions(result, ruleName, {\n actual: primary,\n possible: [true],\n });\n\n if (!validOptions) return;\n // no-op\n };\n};\n\nruleFunction.ruleName = ruleName;\nruleFunction.messages = messages;\nruleFunction.meta = meta;\n\nexport default createPlugin(ruleName, ruleFunction);\n"]}
|
package/docs/api.md
ADDED
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
# Argot public API
|
|
2
|
+
|
|
3
|
+
The API is still in development and likely to change, prior to first published
|
|
4
|
+
version.
|
|
5
|
+
|
|
6
|
+
Node.js 22.18 or newer is required for the CLI and Node APIs. The package is
|
|
7
|
+
native ESM with compiled JavaScript and TypeScript declarations. No TypeScript
|
|
8
|
+
compiler is needed to consume it.
|
|
9
|
+
|
|
10
|
+
All functions below are synchronous and throw on failure. Palette validation
|
|
11
|
+
errors identify the invalid field. Error messages are human-readable; no
|
|
12
|
+
machine-readable error-code API is currently provided. Unless noted, APIs do not
|
|
13
|
+
mutate inputs or write files.
|
|
14
|
+
|
|
15
|
+
## Typical workflows
|
|
16
|
+
|
|
17
|
+
**Primitive palette**
|
|
18
|
+
|
|
19
|
+
1. Build or load a palette seed definition (JSON or in memory).
|
|
20
|
+
2. Use `generatePalette()` to produce structured color shades for each seed in
|
|
21
|
+
the palette, or `generatePaletteCss()` / `renderPaletteCss()` to generate CSS
|
|
22
|
+
custom properties.
|
|
23
|
+
3. In Node, `writePalette()` or `argot palette` writes the CSS file.
|
|
24
|
+
|
|
25
|
+
**Semantic templates**
|
|
26
|
+
|
|
27
|
+
1. `argot generate` or `writeTemplate()` emits a semantic custom properties
|
|
28
|
+
template stylesheet.
|
|
29
|
+
2. Use the palette primitives to assign values to semantic properties in the
|
|
30
|
+
stylesheet.
|
|
31
|
+
|
|
32
|
+
## Entrypoints
|
|
33
|
+
|
|
34
|
+
- `argot-css/palette`: browser-safe palette calculation, CSS rendering,
|
|
35
|
+
definition validation/serialization, and optional CSS color parsing.
|
|
36
|
+
- `argot-css/palette/node`: synchronous definition-file loading and CSS file
|
|
37
|
+
writing. Node only.
|
|
38
|
+
- `argot-css/semantics`: semantic CSS template generation. Node only. Same
|
|
39
|
+
behavior as [`argot semantics`](#semantic-templates).
|
|
40
|
+
- `argot-css/stylelint`: optional Stylelint plugin array.
|
|
41
|
+
- `argot-css/stylelint/config`: optional shareable Stylelint config.
|
|
42
|
+
- `argot-css/tokens/*`: packaged DTCG-shaped JSON files.
|
|
43
|
+
- `argot-css/templates/semantics.css` and
|
|
44
|
+
`argot-css/templates/semantics-extended.css`: static semantic templates.
|
|
45
|
+
|
|
46
|
+
There is no root JavaScript entrypoint. Import from the named subpaths rather
|
|
47
|
+
than internal `src/` or `dist/` paths. Browser-safe means the palette entrypoint
|
|
48
|
+
does not require Node built-ins or browser globals; use a bundler or other
|
|
49
|
+
package-resolution setup to import the npm package in a browser.
|
|
50
|
+
|
|
51
|
+
## Palette definitions
|
|
52
|
+
|
|
53
|
+
To generate a color palette, provide a PaletteDefinition with "seed" colors
|
|
54
|
+
defined using numeric OKLCH values in this format:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"version": 1,
|
|
59
|
+
"colors": [
|
|
60
|
+
{ "name": "gray", "l": 0.6, "c": 0.015, "h": 250 },
|
|
61
|
+
{ "name": "brand", "l": 0.6, "c": 0.2, "h": 250 }
|
|
62
|
+
],
|
|
63
|
+
"options": {
|
|
64
|
+
"lightnessCurve": "inclusive",
|
|
65
|
+
"chromaCurve": "weighted",
|
|
66
|
+
"format": "oklch",
|
|
67
|
+
"gamut": "p3"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`version` must be the number `1`. `colors` must be a nonempty array. Each color
|
|
73
|
+
requires:
|
|
74
|
+
|
|
75
|
+
- `name`: a lowercase name matching `^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$`, such as
|
|
76
|
+
`blue` or `brand-primary`. Do not include the leading `--`.
|
|
77
|
+
- `l`: finite lightness from 0 through 1, not a percentage from 0 through 100.
|
|
78
|
+
- `c`: finite, nonnegative chroma. There is no enforced upper bound; practical
|
|
79
|
+
displayable values depend on lightness, hue, and output gamut (typically below
|
|
80
|
+
0.5).
|
|
81
|
+
- `h`: a finite hue angle in degrees, including for neutral colors. Values are
|
|
82
|
+
not wrapped, so negative angles and angles above 360 are retained.
|
|
83
|
+
|
|
84
|
+
Unknown fields and unsupported versions are rejected, not silently ignored.
|
|
85
|
+
Coordinates are not coerced from strings, clamped, rounded, or thresholded
|
|
86
|
+
during definition validation. Definitions contain no alpha, CSS strings, browser
|
|
87
|
+
state, or filesystem paths.
|
|
88
|
+
|
|
89
|
+
Each color emits `--name`, `--name-1` … `--name-16`. Names must not collide with
|
|
90
|
+
any of those properties for any color in the definition. For example, `blue` and
|
|
91
|
+
`blue-1` cannot both be color names, because `blue` already reserves `--blue-1`.
|
|
92
|
+
|
|
93
|
+
### Options and defaults
|
|
94
|
+
|
|
95
|
+
All options are optional:
|
|
96
|
+
|
|
97
|
+
| Option | Values | Default |
|
|
98
|
+
| ---------------- | ---------------------------------------- | ---------------------------------- |
|
|
99
|
+
| `lightnessCurve` | `'uniform'`, `'inclusive'`, `'centered'` | `'uniform'` |
|
|
100
|
+
| `chromaCurve` | `'centered'`, `'weighted'` | `'centered'` |
|
|
101
|
+
| `format` | `'oklch'`, `'hex'` | `'oklch'` |
|
|
102
|
+
| `gamut` | `'p3'`, `'srgb'` | `'p3'` for OKLCH; `'srgb'` for hex |
|
|
103
|
+
|
|
104
|
+
OKLCH supports either gamut. Hex requires sRGB; `format: 'hex'` with
|
|
105
|
+
`gamut: 'p3'` throws. A color's input space does not select its output gamut.
|
|
106
|
+
|
|
107
|
+
### How scales are built
|
|
108
|
+
|
|
109
|
+
Argot generates palettes with 16 shades ("steps") from light to dark for each
|
|
110
|
+
seed color you provide. Steps are numbered from 1 through 16. The exact colors
|
|
111
|
+
produced are shaped by a lightness curve and a chroma curve, as specified in
|
|
112
|
+
`options`:
|
|
113
|
+
|
|
114
|
+
| Lightness curve | Behavior |
|
|
115
|
+
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
116
|
+
| **Uniform** | Prioritizes uniform lightness across all hues in the palette, based on a hand-crafted lightness scale. Seed color may be rounded slightly to conform. |
|
|
117
|
+
| **Inclusive** | Ensures your seed color is in the final set of color shade, evenly spacing other shades around them. Use if the seeds include precise brand colors you want to preserve. |
|
|
118
|
+
| **Centered** | Places seed color at the middle of each palette. |
|
|
119
|
+
|
|
120
|
+
| Chroma curve | Behavior |
|
|
121
|
+
| ------------ | ------------------------------------------------------------------------------------- |
|
|
122
|
+
| **Centered** | Shades near the center of the scale have the highest chroma. |
|
|
123
|
+
| **Weighted** | Shades near the seed color have the highest chroma. Useful for light/pastel palettes. |
|
|
124
|
+
|
|
125
|
+
After shade calculation, gamut mapping and output rounding is applied to ensure
|
|
126
|
+
all shades are usable on the web. Palette generation does not guarantee
|
|
127
|
+
accessible contrast for semantic pairings.
|
|
128
|
+
|
|
129
|
+
## Browser-safe palette functions
|
|
130
|
+
|
|
131
|
+
Import these from `argot-css/palette`.
|
|
132
|
+
|
|
133
|
+
### `normalizePaletteDefinition(value: unknown): NormalizedPaletteDefinition`
|
|
134
|
+
|
|
135
|
+
Validate external input and return fresh color records with all option defaults
|
|
136
|
+
explicit. Does not calculate steps or map gamut.
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
import { normalizePaletteDefinition } from 'argot-css/palette';
|
|
140
|
+
|
|
141
|
+
const definition = normalizePaletteDefinition({
|
|
142
|
+
version: 1,
|
|
143
|
+
colors: [{ name: 'brand', l: 0.6, c: 0.2, h: 250 }],
|
|
144
|
+
});
|
|
145
|
+
// => {
|
|
146
|
+
// version: 1,
|
|
147
|
+
// colors: [{ name: 'brand', l: 0.6, c: 0.2, h: 250 }],
|
|
148
|
+
// options: {
|
|
149
|
+
// lightnessCurve: 'uniform',
|
|
150
|
+
// chromaCurve: 'centered',
|
|
151
|
+
// format: 'oklch',
|
|
152
|
+
// gamut: 'p3',
|
|
153
|
+
// },
|
|
154
|
+
// }
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
The result remains a version-1 definition suitable for generation or export. Use
|
|
158
|
+
this boundary for data from JSON files, browser forms, or another tool.
|
|
159
|
+
|
|
160
|
+
### `serializePaletteDefinition(definition: PaletteDefinition): string`
|
|
161
|
+
|
|
162
|
+
Validate/normalize the definition and return two-space-indented JSON with a
|
|
163
|
+
trailing newline and explicit defaults. Serializes generation inputs, not
|
|
164
|
+
generated steps or CSS.
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
import { serializePaletteDefinition } from 'argot-css/palette';
|
|
168
|
+
|
|
169
|
+
const portableJson = serializePaletteDefinition({
|
|
170
|
+
version: 1,
|
|
171
|
+
colors: [{ name: 'brand', l: 0.6, c: 0.2, h: 250 }],
|
|
172
|
+
});
|
|
173
|
+
// => `{
|
|
174
|
+
// "version": 1,
|
|
175
|
+
// "colors": [
|
|
176
|
+
// {
|
|
177
|
+
// "name": "brand",
|
|
178
|
+
// "l": 0.6,
|
|
179
|
+
// "c": 0.2,
|
|
180
|
+
// "h": 250
|
|
181
|
+
// }
|
|
182
|
+
// ],
|
|
183
|
+
// "options": {
|
|
184
|
+
// "lightnessCurve": "uniform",
|
|
185
|
+
// "chromaCurve": "centered",
|
|
186
|
+
// "format": "oklch",
|
|
187
|
+
// "gamut": "p3"
|
|
188
|
+
// }
|
|
189
|
+
// }\n`
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### `parseCssColor(value: string): OklchColor`
|
|
193
|
+
|
|
194
|
+
Optional input adapter that converts a standalone opaque CSS color into numeric
|
|
195
|
+
`{ l, c, h }`. It accepts supported CSS color syntax such as hex, named colors,
|
|
196
|
+
and `oklch()`. It rejects transparent colors, malformed colors, and
|
|
197
|
+
context-dependent values such as `currentColor` and `var(--brand)`.
|
|
198
|
+
|
|
199
|
+
Achromatic CSS colors with no hue receive `h: 0`. Tiny floating-point excursions
|
|
200
|
+
at the lightness endpoints caused by conversion are tolerated and clamped here,
|
|
201
|
+
not in numeric definition validation. No output-gamut mapping is performed.
|
|
202
|
+
|
|
203
|
+
```js
|
|
204
|
+
import { parseCssColor } from 'argot-css/palette';
|
|
205
|
+
|
|
206
|
+
const seed = parseCssColor('#663399');
|
|
207
|
+
// => { l: 0.4402…, c: 0.1602…, h: 303.37… }
|
|
208
|
+
|
|
209
|
+
const definition = {
|
|
210
|
+
version: 1,
|
|
211
|
+
colors: [{ name: 'brand', ...seed }],
|
|
212
|
+
};
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### `generatePalette(definition: PaletteDefinition): Palette`
|
|
216
|
+
|
|
217
|
+
Validate inputs and return a fresh structured palette. The result contains raw,
|
|
218
|
+
unrounded OKLCH coordinates before gamut mapping:
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
interface Palette {
|
|
222
|
+
version: 1;
|
|
223
|
+
options: Required<PaletteOptions>;
|
|
224
|
+
colors: {
|
|
225
|
+
name: string;
|
|
226
|
+
baseStep: number;
|
|
227
|
+
steps: { step: number; l: number; c: number; h: number }[];
|
|
228
|
+
}[];
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Color order follows input order. `step` and `baseStep` are **one-based**, from 1
|
|
233
|
+
through 16. Array indexes remain zero-based.
|
|
234
|
+
|
|
235
|
+
```js
|
|
236
|
+
import { generatePalette } from 'argot-css/palette';
|
|
237
|
+
|
|
238
|
+
const palette = generatePalette({
|
|
239
|
+
version: 1,
|
|
240
|
+
colors: [{ name: 'brand', l: 0.6, c: 0.2, h: 250 }],
|
|
241
|
+
options: { lightnessCurve: 'inclusive' },
|
|
242
|
+
});
|
|
243
|
+
// => {
|
|
244
|
+
// version: 1,
|
|
245
|
+
// options: { lightnessCurve: 'inclusive', chromaCurve: 'centered',
|
|
246
|
+
// format: 'oklch', gamut: 'p3' },
|
|
247
|
+
// colors: [{
|
|
248
|
+
// name: 'brand',
|
|
249
|
+
// baseStep: 8,
|
|
250
|
+
// steps: [
|
|
251
|
+
// { step: 1, l: 0.98, c: 0.028, h: 250 },
|
|
252
|
+
// // ... steps 2–7 ...
|
|
253
|
+
// { step: 8, l: 0.6, c: 0.2, h: 250 },
|
|
254
|
+
// // ... steps 9–15 ...
|
|
255
|
+
// { step: 16, l: 0.1, c: 0.048, h: 250 },
|
|
256
|
+
// ],
|
|
257
|
+
// }],
|
|
258
|
+
// }
|
|
259
|
+
|
|
260
|
+
const brand = palette.colors[0];
|
|
261
|
+
const rawBaseColor = brand.steps[brand.baseStep - 1];
|
|
262
|
+
// => { step: 8, l: 0.6, c: 0.2, h: 250 }
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Format/gamut options are retained in the result but do not change its raw steps.
|
|
266
|
+
|
|
267
|
+
### `renderPaletteCss(palette: Palette): string`
|
|
268
|
+
|
|
269
|
+
Render a generated model to a `:root` block containing `--name-1` through
|
|
270
|
+
`--name-16`, followed by `--name: var(--name-N)` using `baseStep`. Returns CSS
|
|
271
|
+
with a generated-file comment and trailing newline.
|
|
272
|
+
|
|
273
|
+
Colors are mapped to the selected gamut using Color.js's `css` mapping method.
|
|
274
|
+
OKLCH serialization uses Color.js precision `6`; hex is six-digit sRGB. Rounding
|
|
275
|
+
is deferred until serialization. A neutral hue may serialize as `none`, which is
|
|
276
|
+
valid CSS.
|
|
277
|
+
|
|
278
|
+
Pass a model from `generatePalette()`. This is not a general-purpose validator
|
|
279
|
+
for arbitrary imported palette models; import portable definitions instead.
|
|
280
|
+
|
|
281
|
+
```js
|
|
282
|
+
import { generatePalette, renderPaletteCss } from 'argot-css/palette';
|
|
283
|
+
|
|
284
|
+
const css = renderPaletteCss(
|
|
285
|
+
generatePalette({
|
|
286
|
+
version: 1,
|
|
287
|
+
colors: [{ name: 'brand', l: 0.6, c: 0.2, h: 250 }],
|
|
288
|
+
options: { lightnessCurve: 'inclusive' },
|
|
289
|
+
}),
|
|
290
|
+
);
|
|
291
|
+
// => `/* Generated by Argot. */
|
|
292
|
+
// :root {
|
|
293
|
+
// --brand-1: oklch(97.6518% 0.017936 219.617);
|
|
294
|
+
// /* ... --brand-2 through --brand-15 ... */
|
|
295
|
+
// --brand-16: oklch(10.219% 0.045256 256.462);
|
|
296
|
+
// --brand: var(--brand-8);
|
|
297
|
+
// }
|
|
298
|
+
// `
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### `generatePaletteCss(definition: PaletteDefinition): string`
|
|
302
|
+
|
|
303
|
+
Convenience composition of `generatePalette()` and `renderPaletteCss()`:
|
|
304
|
+
|
|
305
|
+
```js
|
|
306
|
+
import { generatePaletteCss } from 'argot-css/palette';
|
|
307
|
+
|
|
308
|
+
const css = generatePaletteCss({
|
|
309
|
+
version: 1,
|
|
310
|
+
colors: [{ name: 'brand', l: 0.6, c: 0.2, h: 250 }],
|
|
311
|
+
options: { format: 'hex' },
|
|
312
|
+
});
|
|
313
|
+
// => `/* Generated by Argot. */
|
|
314
|
+
// :root {
|
|
315
|
+
// --brand-1: #ebfaff;
|
|
316
|
+
// /* ... --brand-2 through --brand-15 ... */
|
|
317
|
+
// --brand-16: #000312;
|
|
318
|
+
// --brand: var(--brand-8);
|
|
319
|
+
// }
|
|
320
|
+
// `
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Exported palette types
|
|
324
|
+
|
|
325
|
+
- Inputs: `OklchColor`, `SeedColor`, `PaletteDefinition`, `PaletteOptions`.
|
|
326
|
+
- Validated definitions: `NormalizedPaletteDefinition`,
|
|
327
|
+
`NormalizedPaletteOptions`.
|
|
328
|
+
- Generated models: `Palette`, `PaletteScale`, `PaletteStep`.
|
|
329
|
+
- Option unions: `LightnessCurve`, `ChromaCurve`, `ColorFormat`, `ColorGamut`.
|
|
330
|
+
|
|
331
|
+
```ts
|
|
332
|
+
import { generatePaletteCss, type PaletteDefinition } from 'argot-css/palette';
|
|
333
|
+
|
|
334
|
+
const definition = {
|
|
335
|
+
version: 1,
|
|
336
|
+
colors: [{ name: 'brand', l: 0.6, c: 0.2, h: 250 }],
|
|
337
|
+
} satisfies PaletteDefinition;
|
|
338
|
+
const css: string = generatePaletteCss(definition);
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
TypeScript types do not replace runtime validation of imported JSON.
|
|
342
|
+
|
|
343
|
+
## Node palette file functions
|
|
344
|
+
|
|
345
|
+
Import these from `argot-css/palette/node`. Neither is part of the browser-safe
|
|
346
|
+
entrypoint. Relative paths resolve against `process.cwd()`.
|
|
347
|
+
|
|
348
|
+
### `loadPaletteDefinition(filename: string): NormalizedPaletteDefinition`
|
|
349
|
+
|
|
350
|
+
Read UTF-8 JSON synchronously, parse it, and validate/normalize it. Read, JSON,
|
|
351
|
+
and definition errors include the resolved input path.
|
|
352
|
+
|
|
353
|
+
```js
|
|
354
|
+
import { loadPaletteDefinition } from 'argot-css/palette/node';
|
|
355
|
+
|
|
356
|
+
// ./palette.json:
|
|
357
|
+
// {
|
|
358
|
+
// "version": 1,
|
|
359
|
+
// "colors": [{ "name": "brand", "l": 0.6, "c": 0.2, "h": 250 }]
|
|
360
|
+
// }
|
|
361
|
+
|
|
362
|
+
const definition = loadPaletteDefinition('./palette.json');
|
|
363
|
+
// => {
|
|
364
|
+
// version: 1,
|
|
365
|
+
// colors: [{ name: 'brand', l: 0.6, c: 0.2, h: 250 }],
|
|
366
|
+
// options: {
|
|
367
|
+
// lightnessCurve: 'uniform',
|
|
368
|
+
// chromaCurve: 'centered',
|
|
369
|
+
// format: 'oklch',
|
|
370
|
+
// gamut: 'p3',
|
|
371
|
+
// },
|
|
372
|
+
// }
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### `writePalette(outPath, definition, options?): WritePaletteResult`
|
|
376
|
+
|
|
377
|
+
Generate CSS and synchronously write it to the designated output file.
|
|
378
|
+
Parameters are `outPath: string`, `definition: PaletteDefinition`, and optional
|
|
379
|
+
`options: WritePaletteOptions`.
|
|
380
|
+
|
|
381
|
+
```ts
|
|
382
|
+
interface WritePaletteOptions {
|
|
383
|
+
force?: boolean; // default false
|
|
384
|
+
dryRun?: boolean; // default false
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
interface WritePaletteResult {
|
|
388
|
+
path: string; // absolute output path
|
|
389
|
+
css: string; // generated CSS, including for a dry run
|
|
390
|
+
written: boolean;
|
|
391
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
- Missing parent directories are created only for a real write.
|
|
395
|
+
- Existing files are refused unless `force: true`. Dry runs use the same path
|
|
396
|
+
checks, so previewing over an existing file still needs `force: true` even
|
|
397
|
+
though nothing is written.
|
|
398
|
+
- Output directories and final-path symlinks are refused even with `force`.
|
|
399
|
+
- Dry runs validate and render but do not create directories or modify output.
|
|
400
|
+
- Invalid definitions fail before output directories or files are created.
|
|
401
|
+
|
|
402
|
+
Filesystem failures throw. This function does not save the definition or update
|
|
403
|
+
other project files. Choose distinct input and output locations.
|
|
404
|
+
|
|
405
|
+
```js
|
|
406
|
+
import { writeFileSync } from 'node:fs';
|
|
407
|
+
import { serializePaletteDefinition } from 'argot-css/palette';
|
|
408
|
+
import { loadPaletteDefinition, writePalette } from 'argot-css/palette/node';
|
|
409
|
+
|
|
410
|
+
const definition = loadPaletteDefinition('./palette.json');
|
|
411
|
+
|
|
412
|
+
const preview = writePalette('./styles/primitives.css', definition, {
|
|
413
|
+
dryRun: true,
|
|
414
|
+
});
|
|
415
|
+
// => { path: '/absolute/path/to/styles/primitives.css', written: false, css: '…' }
|
|
416
|
+
|
|
417
|
+
const result = writePalette('./styles/primitives.css', definition);
|
|
418
|
+
// => { path: '/absolute/path/to/styles/primitives.css', written: true, css: '…' }
|
|
419
|
+
|
|
420
|
+
// Optional export of the portable inputs, separate from the CSS output.
|
|
421
|
+
writeFileSync('./palette-export.json', serializePaletteDefinition(definition));
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
`WritePaletteOptions` and `WritePaletteResult` are exported types from this Node
|
|
425
|
+
entrypoint.
|
|
426
|
+
|
|
427
|
+
## CLI
|
|
428
|
+
|
|
429
|
+
Install the package and use `argot` in npm scripts, or invoke it with
|
|
430
|
+
`npm exec --package=argot-css -- argot ...`.
|
|
431
|
+
|
|
432
|
+
```sh
|
|
433
|
+
argot palette ./palette.json
|
|
434
|
+
argot palette ./palette.json ./styles/primitives.css
|
|
435
|
+
argot palette ./palette.json ./styles/primitives.css --dry-run
|
|
436
|
+
argot palette ./palette.json ./styles/primitives.css --force
|
|
437
|
+
argot palette --help
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
The default palette output is `./primitives.css`. The CLI uses
|
|
441
|
+
[`writePalette()`](#writepaletteoutpath-definition-options-writepaletteresult)'s
|
|
442
|
+
overwrite and dry-run rules, rejects identical resolved input/output paths, and
|
|
443
|
+
reports failures on stderr with a nonzero exit status. It never runs Stylelint
|
|
444
|
+
or semantic generation as a side effect.
|
|
445
|
+
|
|
446
|
+
From a source checkout, `npm run dev -- palette ...` runs the same command using
|
|
447
|
+
native TypeScript. The installed executable uses compiled JavaScript.
|
|
448
|
+
|
|
449
|
+
### Semantic templates
|
|
450
|
+
|
|
451
|
+
Same behavior as [`argot-css/semantics`](#semantic-generation-library):
|
|
452
|
+
|
|
453
|
+
```sh
|
|
454
|
+
argot generate
|
|
455
|
+
argot generate ./styles/semantics.css --extended
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
Default output is `./semantics.css`, with core semantic names and empty values.
|
|
459
|
+
`--extended` includes both tiers. Assign values in the consumer project;
|
|
460
|
+
primitive generation does not automatically populate semantic mappings.
|
|
461
|
+
|
|
462
|
+
**Unlike the palette command, semantic generation currently overwrites existing
|
|
463
|
+
files without `--force`.** Its CLI refuses output directories.
|
|
464
|
+
|
|
465
|
+
## Semantic generation library
|
|
466
|
+
|
|
467
|
+
Import from `argot-css/semantics` (CLI:
|
|
468
|
+
[`argot generate`](#semantic-templates)):
|
|
469
|
+
|
|
470
|
+
- `generateCss(options?: TokenOptions): string`: load packaged semantic tokens
|
|
471
|
+
and render their CSS template. `extended` defaults to `false`.
|
|
472
|
+
- `renderCss(sections: readonly TokenSection[]): string`: render already-loaded
|
|
473
|
+
token sections in order.
|
|
474
|
+
- `writeTemplate(outPath: string, options?: TokenOptions): string`: create
|
|
475
|
+
parent directories, write the template, and return its absolute path. Existing
|
|
476
|
+
files are overwritten; filesystem errors throw.
|
|
477
|
+
|
|
478
|
+
This entrypoint exports `TokenOptions`, `TokenRecord`, and `TokenSection`.
|
|
479
|
+
`TokenOptions` has optional boolean `extended`. A section has `file`, `label`,
|
|
480
|
+
and `tokens`; token records carry `name`, `value`, `description`, `tier`,
|
|
481
|
+
`type`, `usage`, `pairsWith`, and `related`. Empty/null values render as empty
|
|
482
|
+
declarations. Loading and indexing internals are not public package exports.
|
|
483
|
+
|
|
484
|
+
## Optional Stylelint integration
|
|
485
|
+
|
|
486
|
+
Requires the optional Stylelint 16 peer dependency:
|
|
487
|
+
|
|
488
|
+
```js
|
|
489
|
+
export default {
|
|
490
|
+
extends: ['argot-css/stylelint/config'],
|
|
491
|
+
};
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
`argot-css/stylelint` default-exports the plugin array. The config entrypoint
|
|
495
|
+
registers it and enables `argot/valid-token`.
|
|
496
|
+
|
|
497
|
+
**The rule is currently a no-op placeholder**, not token-name enforcement,
|
|
498
|
+
contrast validation, or build-time linting.
|
|
499
|
+
|
|
500
|
+
## Static data and styles
|
|
501
|
+
|
|
502
|
+
Token JSON uses the packaged DTCG-shaped vocabulary, including descriptions,
|
|
503
|
+
tiers, and optional relationship metadata. It is not a promise of full DTCG
|
|
504
|
+
interchange support.
|
|
505
|
+
|
|
506
|
+
```js
|
|
507
|
+
import textTokens from 'argot-css/tokens/color-text.json' with { type: 'json' };
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
The two CSS templates export core or core-plus-extended semantic property names
|
|
511
|
+
for projects that prefer a static import over
|
|
512
|
+
[`generate` / `writeTemplate`](#semantic-generation-library). CSS import
|
|
513
|
+
resolution depends on the consumer's build tooling. No PostCSS preset or
|
|
514
|
+
processing command is shipped.
|