argot-css 0.0.1 → 0.1.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/LICENSE.md +1 -1
- package/README.md +23 -244
- package/dist/cli/getConfig.d.ts +11 -0
- package/dist/cli/getConfig.js +37 -0
- package/dist/cli/getConfig.js.map +1 -0
- package/dist/cli/print.js +1 -1
- package/dist/cli/print.js.map +1 -1
- package/dist/cli/run.js +20 -7
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/usage.d.ts +1 -1
- package/dist/cli/usage.js +8 -5
- package/dist/cli/usage.js.map +1 -1
- package/dist/config/getConfig.d.ts +1 -0
- package/dist/config/getConfig.js +38 -0
- package/dist/config/getConfig.js.map +1 -0
- package/dist/config/types.d.ts +31 -0
- package/dist/config/types.js +2 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config/util.d.ts +2 -0
- package/dist/config/util.js +4 -0
- package/dist/config/util.js.map +1 -0
- package/dist/io/safeWrite.d.ts +24 -0
- package/dist/io/safeWrite.js +50 -0
- package/dist/io/safeWrite.js.map +1 -0
- package/dist/lib/writeOutput.d.ts +32 -0
- package/dist/lib/writeOutput.js +88 -0
- package/dist/lib/writeOutput.js.map +1 -0
- package/dist/palette/cli.d.ts +2 -1
- package/dist/palette/cli.js +23 -12
- package/dist/palette/cli.js.map +1 -1
- package/dist/palette/generateName.d.ts +1 -1
- package/dist/palette/generatePalette.d.ts +2 -1
- package/dist/palette/generatePalette.js +1 -2
- package/dist/palette/generatePalette.js.map +1 -1
- package/dist/palette/index.d.ts +3 -2
- package/dist/palette/index.js +1 -1
- package/dist/palette/index.js.map +1 -1
- package/dist/palette/node.d.ts +7 -6
- package/dist/palette/node.js +6 -33
- package/dist/palette/node.js.map +1 -1
- package/dist/palette/render.d.ts +2 -1
- package/dist/palette/render.js +8 -5
- package/dist/palette/render.js.map +1 -1
- package/dist/palette/types.d.ts +30 -23
- package/dist/palette/types.js +26 -1
- package/dist/palette/types.js.map +1 -1
- package/dist/palette/validation.d.ts +5 -6
- package/dist/palette/validation.js +68 -56
- package/dist/palette/validation.js.map +1 -1
- package/dist/processor/cli.d.ts +2 -1
- package/dist/processor/cli.js +20 -7
- package/dist/processor/cli.js.map +1 -1
- package/dist/processor/index.d.ts +2 -1
- package/dist/processor/index.js +37 -14
- package/dist/processor/index.js.map +1 -1
- package/dist/processor/stylelintDefault.d.ts +4 -0
- package/dist/processor/stylelintDefault.js +5 -14
- package/dist/processor/stylelintDefault.js.map +1 -1
- package/dist/scaffold/cli.d.ts +3 -0
- package/dist/scaffold/cli.js +32 -0
- package/dist/scaffold/cli.js.map +1 -0
- package/dist/scaffold/templates.d.ts +6 -0
- package/dist/scaffold/templates.js +57 -0
- package/dist/scaffold/templates.js.map +1 -0
- package/dist/scaffold/writeScaffold.d.ts +12 -0
- package/dist/scaffold/writeScaffold.js +49 -0
- package/dist/scaffold/writeScaffold.js.map +1 -0
- package/dist/semantics/cli.d.ts +2 -1
- package/dist/semantics/cli.js +36 -29
- package/dist/semantics/cli.js.map +1 -1
- package/dist/semantics/generate.d.ts +8 -1
- package/dist/semantics/generate.js +4 -7
- package/dist/semantics/generate.js.map +1 -1
- package/dist/semantics/load-tokens.d.ts +2 -2
- package/dist/semantics/load-tokens.js.map +1 -1
- package/dist/stylelint/config.d.ts +2 -2
- package/dist/stylelint/config.js +3 -5
- package/dist/stylelint/config.js.map +1 -1
- package/dist/stylelint/index.d.ts +2 -2
- package/dist/stylelint/index.js +2 -2
- package/dist/stylelint/index.js.map +1 -1
- package/dist/stylelint/rules/colorContrast.d.ts +4 -0
- package/dist/stylelint/rules/colorContrast.js +91 -0
- package/dist/stylelint/rules/colorContrast.js.map +1 -0
- package/dist/stylelint/rules/util.d.ts +13 -0
- package/dist/stylelint/rules/util.js +66 -0
- package/dist/stylelint/rules/util.js.map +1 -0
- package/dist/stylelint/rules/valid-token.js +1 -1
- package/dist/stylelint/rules/valid-token.js.map +1 -1
- package/package.json +7 -8
- package/templates/styles.css +3 -2
- package/docs/api.md +0 -514
- /package/templates/{semantics.css → semantics-core.css} +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
import { writeScaffold } from "./writeScaffold.js";
|
|
3
|
+
import { print } from "../cli/print.js";
|
|
4
|
+
import { ANSI_BLUE, ANSI_YELLOW } from "../cli/ansiColors.js";
|
|
5
|
+
import { getScaffoldDirectory } from "../config/util.js";
|
|
6
|
+
const USAGE = 'Usage: argot scaffold [--directory "./path/to/directory"] [--force] [--dry-run]';
|
|
7
|
+
function runScaffold(args, config = {}) {
|
|
8
|
+
const { values } = parseArgs({
|
|
9
|
+
args,
|
|
10
|
+
options: {
|
|
11
|
+
directory: { type: 'string' },
|
|
12
|
+
force: { type: 'boolean', default: false },
|
|
13
|
+
'dry-run': { type: 'boolean', default: false },
|
|
14
|
+
help: { type: 'boolean', short: 'h', default: false },
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
const directory = values.directory || getScaffoldDirectory(config);
|
|
18
|
+
if (values.help || !directory) {
|
|
19
|
+
print(USAGE, ANSI_YELLOW);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const result = writeScaffold(directory, config, {
|
|
23
|
+
force: values.force,
|
|
24
|
+
dryRun: values['dry-run'],
|
|
25
|
+
});
|
|
26
|
+
for (const { path: filePath, written } of result.files) {
|
|
27
|
+
print(`${written ? 'Wrote' : 'Would write'} ${filePath}`, ANSI_BLUE);
|
|
28
|
+
}
|
|
29
|
+
print('');
|
|
30
|
+
}
|
|
31
|
+
export { runScaffold };
|
|
32
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/scaffold/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;A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AC,CAAC;IACvE,CAAC;IACD,KAAK,CAAC,EAAE,CAAC,CAAC;AACZ,CAAC;AAED,OAAO,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import { parseArgs } from 'node:util';\nimport { writeScaffold } from './writeScaffold.ts';\nimport { print } from '../cli/print.ts';\nimport { ANSI_BLUE, ANSI_YELLOW } from '../cli/ansiColors.ts';\nimport { getScaffoldDirectory } from '../config/util.ts';\nimport type { ArgotConfig } from '../config/types.ts';\n\nconst USAGE =\n 'Usage: argot scaffold [--directory \"./path/to/directory\"] [--force] [--dry-run]';\n\nfunction runScaffold(args: string[], config: ArgotConfig = {}): void {\n const { values } = parseArgs({\n args,\n options: {\n directory: { type: 'string' },\n force: { type: 'boolean', default: false },\n 'dry-run': { type: 'boolean', default: false },\n help: { type: 'boolean', short: 'h', default: false },\n },\n });\n\n const directory = values.directory || getScaffoldDirectory(config);\n\n if (values.help || !directory) {\n print(USAGE, ANSI_YELLOW);\n return;\n }\n\n const result = writeScaffold(directory, config, {\n force: values.force,\n dryRun: values['dry-run'],\n });\n for (const { path: filePath, written } of result.files) {\n print(`${written ? 'Wrote' : 'Would write'} ${filePath}`, ANSI_BLUE);\n }\n print('');\n}\n\nexport { runScaffold };\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export const templates = [
|
|
2
|
+
{
|
|
3
|
+
file: 'index.css',
|
|
4
|
+
contents: `@layer reset, base, theme, layout, modules, utilities;
|
|
5
|
+
|
|
6
|
+
@import 'reset.css' layer(reset);
|
|
7
|
+
@import 'base.css' layer(base);
|
|
8
|
+
@import 'vars-primitive.css' layer(theme);
|
|
9
|
+
@import 'vars-semantic.css' layer(theme);
|
|
10
|
+
@import 'layout.css' layer(layout);
|
|
11
|
+
@import 'modules/index.css' layer(modules);
|
|
12
|
+
`,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
file: 'reset.css',
|
|
16
|
+
contents: `*,
|
|
17
|
+
*::before,
|
|
18
|
+
*::after {
|
|
19
|
+
box-sizing: border-box;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
html {
|
|
23
|
+
-webkit-font-smoothing: antialiased;
|
|
24
|
+
text-rendering: optimizeLegibility;
|
|
25
|
+
font-synthesis: none;
|
|
26
|
+
-moz-text-size-adjust: none;
|
|
27
|
+
-webkit-text-size-adjust: none;
|
|
28
|
+
text-size-adjust: none;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
body {
|
|
32
|
+
margin: unset;
|
|
33
|
+
font-size-adjust: from-font;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
button,
|
|
37
|
+
input,
|
|
38
|
+
textarea,
|
|
39
|
+
select {
|
|
40
|
+
font: inherit;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
img,
|
|
44
|
+
picture,
|
|
45
|
+
svg,
|
|
46
|
+
canvas {
|
|
47
|
+
display: block;
|
|
48
|
+
max-inline-size: 100%;
|
|
49
|
+
block-size: auto;
|
|
50
|
+
}
|
|
51
|
+
`,
|
|
52
|
+
},
|
|
53
|
+
{ file: 'base.css', contents: '' },
|
|
54
|
+
{ file: 'layout.css', contents: '' },
|
|
55
|
+
{ file: 'modules/index.css', contents: '' },
|
|
56
|
+
];
|
|
57
|
+
//# sourceMappingURL=templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../src/scaffold/templates.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,SAAS,GAAe;IACnC;QACE,IAAI,EAAE,WAAW;QACjB,QAAQ,EAAE;;;;;;;;CAQb;KACE;IACD;QACE,IAAI,EAAE,WAAW;QACjB,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCb;KACE;IACD,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE;IAClC,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE;IACpC,EAAE,IAAI,EAAE,mBAAmB,EAAE,QAAQ,EAAE,EAAE,EAAE;CAC5C,CAAC","sourcesContent":["interface Template {\n file: string;\n contents: string;\n}\n\nexport const templates: Template[] = [\n {\n file: 'index.css',\n contents: `@layer reset, base, theme, layout, modules, utilities;\n\n@import 'reset.css' layer(reset);\n@import 'base.css' layer(base);\n@import 'vars-primitive.css' layer(theme);\n@import 'vars-semantic.css' layer(theme);\n@import 'layout.css' layer(layout);\n@import 'modules/index.css' layer(modules);\n`,\n },\n {\n file: 'reset.css',\n contents: `*,\n*::before,\n*::after {\n box-sizing: border-box;\n}\n\nhtml {\n -webkit-font-smoothing: antialiased;\n text-rendering: optimizeLegibility;\n font-synthesis: none;\n -moz-text-size-adjust: none;\n -webkit-text-size-adjust: none;\n text-size-adjust: none;\n}\n\nbody {\n margin: unset;\n font-size-adjust: from-font;\n}\n\nbutton,\ninput,\ntextarea,\nselect {\n font: inherit;\n}\n\nimg,\npicture,\nsvg,\ncanvas {\n display: block;\n max-inline-size: 100%;\n block-size: auto;\n}\n`,\n },\n { file: 'base.css', contents: '' },\n { file: 'layout.css', contents: '' },\n { file: 'modules/index.css', contents: '' },\n];\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { WriteOutputOptions } from '../lib/writeOutput.ts';
|
|
2
|
+
import type { ArgotConfig } from '../config/types.ts';
|
|
3
|
+
export type WriteScaffoldOptions = WriteOutputOptions;
|
|
4
|
+
export interface WriteScaffoldFileResult {
|
|
5
|
+
path: string;
|
|
6
|
+
written: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface WriteScaffoldResult {
|
|
9
|
+
files: WriteScaffoldFileResult[];
|
|
10
|
+
}
|
|
11
|
+
declare function writeScaffold(directory: string, config?: ArgotConfig, { force, dryRun }?: WriteScaffoldOptions): WriteScaffoldResult;
|
|
12
|
+
export { writeScaffold };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { assertWritableOutputFile, writeOutput } from "../lib/writeOutput.js";
|
|
3
|
+
import { templates } from "./templates.js";
|
|
4
|
+
import { writePalette } from "../palette/node.js";
|
|
5
|
+
import { writeTemplate } from "../semantics/generate.js";
|
|
6
|
+
function writeScaffold(directory, config = {}, { force = false, dryRun = false } = {}) {
|
|
7
|
+
const root = path.resolve(directory);
|
|
8
|
+
const palettePath = path.join(root, 'vars-primitive.css');
|
|
9
|
+
const semanticsPath = path.join(root, 'vars-semantic.css');
|
|
10
|
+
const templateTargets = templates.map((template) => ({
|
|
11
|
+
...template,
|
|
12
|
+
resolved: path.resolve(root, template.file),
|
|
13
|
+
}));
|
|
14
|
+
const assertOptions = {
|
|
15
|
+
force,
|
|
16
|
+
root,
|
|
17
|
+
getExistsMessage: getScaffoldExistsMessage,
|
|
18
|
+
};
|
|
19
|
+
for (const { resolved } of templateTargets) {
|
|
20
|
+
assertWritableOutputFile(resolved, assertOptions);
|
|
21
|
+
}
|
|
22
|
+
assertWritableOutputFile(palettePath, assertOptions);
|
|
23
|
+
assertWritableOutputFile(semanticsPath, assertOptions);
|
|
24
|
+
const writeOpts = { force, dryRun, skipAssert: true, root };
|
|
25
|
+
const files = [];
|
|
26
|
+
for (const { resolved, contents } of templateTargets) {
|
|
27
|
+
const result = writeOutput(resolved, contents, writeOpts);
|
|
28
|
+
files.push({ path: result.path, written: result.written });
|
|
29
|
+
}
|
|
30
|
+
const paletteResult = writePalette(palettePath, paletteDefinition(config), writeOpts);
|
|
31
|
+
files.push({ path: paletteResult.path, written: paletteResult.written });
|
|
32
|
+
const semanticsResult = writeTemplate(semanticsPath, { extended: semanticsExtended(config) }, writeOpts);
|
|
33
|
+
files.push({ path: semanticsResult.path, written: semanticsResult.written });
|
|
34
|
+
return { files };
|
|
35
|
+
}
|
|
36
|
+
function getScaffoldExistsMessage(resolved) {
|
|
37
|
+
return `Scaffold file already exists: ${resolved}. Use --force to replace scaffold files.`;
|
|
38
|
+
}
|
|
39
|
+
function paletteDefinition(config) {
|
|
40
|
+
if (!config.palette)
|
|
41
|
+
return {};
|
|
42
|
+
const { output, ...definition } = config.palette;
|
|
43
|
+
return definition;
|
|
44
|
+
}
|
|
45
|
+
function semanticsExtended(config) {
|
|
46
|
+
return config.semantics?.set === 'extended';
|
|
47
|
+
}
|
|
48
|
+
export { writeScaffold };
|
|
49
|
+
//# sourceMappingURL=writeScaffold.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeScaffold.js","sourceRoot":"","sources":["../../src/scaffold/writeScaffold.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAE9E,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAczD,SAAS,aAAa,CACpB,SAAiB,EACjB,SAAsB,EAAE,EACxB,EAAE,KAAK,GAAG,KAAK,EAAE,MAAM,GAAG,KAAK,KAA2B,EAAE;IAE5D,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACrC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;IAC1D,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IAE3D,MAAM,eAAe,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACnD,GAAG,QAAQ;QACX,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;KAC5C,CAAC,CAAC,CAAC;IAEJ,MAAM,aAAa,GAAG;QACpB,KAAK;QACL,IAAI;QACJ,gBAAgB,EAAE,wBA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Q,0CAA0C,CAAC;AAC7F,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAmB;IAC5C,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAC/B,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC;IACjD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAmB;IAC5C,OAAO,MAAM,CAAC,SAAS,EAAE,GAAG,KAAK,UAAU,CAAC;AAC9C,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import path from 'node:path';\nimport { assertWritableOutputFile, writeOutput } from '../lib/writeOutput.ts';\nimport type { WriteOutputOptions } from '../lib/writeOutput.ts';\nimport { templates } from './templates.ts';\nimport { writePalette } from '../palette/node.ts';\nimport { writeTemplate } from '../semantics/generate.ts';\nimport type { ArgotConfig, PaletteDefinition } from '../config/types.ts';\n\nexport type WriteScaffoldOptions = WriteOutputOptions;\n\nexport interface WriteScaffoldFileResult {\n path: string;\n written: boolean;\n}\n\nexport interface WriteScaffoldResult {\n files: WriteScaffoldFileResult[];\n}\n\nfunction writeScaffold(\n directory: string,\n config: ArgotConfig = {},\n { force = false, dryRun = false }: WriteScaffoldOptions = {},\n): WriteScaffoldResult {\n const root = path.resolve(directory);\n const palettePath = path.join(root, 'vars-primitive.css');\n const semanticsPath = path.join(root, 'vars-semantic.css');\n\n const templateTargets = templates.map((template) => ({\n ...template,\n resolved: path.resolve(root, template.file),\n }));\n\n const assertOptions = {\n force,\n root,\n getExistsMessage: getScaffoldExistsMessage,\n };\n for (const { resolved } of templateTargets) {\n assertWritableOutputFile(resolved, assertOptions);\n }\n assertWritableOutputFile(palettePath, assertOptions);\n assertWritableOutputFile(semanticsPath, assertOptions);\n\n const writeOpts = { force, dryRun, skipAssert: true, root };\n const files: WriteScaffoldFileResult[] = [];\n\n for (const { resolved, contents } of templateTargets) {\n const result = writeOutput(resolved, contents, writeOpts);\n files.push({ path: result.path, written: result.written });\n }\n\n const paletteResult = writePalette(\n palettePath,\n paletteDefinition(config),\n writeOpts,\n );\n files.push({ path: paletteResult.path, written: paletteResult.written });\n\n const semanticsResult = writeTemplate(\n semanticsPath,\n { extended: semanticsExtended(config) },\n writeOpts,\n );\n files.push({ path: semanticsResult.path, written: semanticsResult.written });\n\n return { files };\n}\n\nfunction getScaffoldExistsMessage(resolved: string): string {\n return `Scaffold file already exists: ${resolved}. Use --force to replace scaffold files.`;\n}\n\nfunction paletteDefinition(config: ArgotConfig): PaletteDefinition {\n if (!config.palette) return {};\n const { output, ...definition } = config.palette;\n return definition;\n}\n\nfunction semanticsExtended(config: ArgotConfig): boolean {\n return config.semantics?.set === 'extended';\n}\n\nexport { writeScaffold };\n"]}
|
package/dist/semantics/cli.d.ts
CHANGED
package/dist/semantics/cli.js
CHANGED
|
@@ -1,34 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from 'node:path';
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
3
2
|
import { writeTemplate } from "./generate.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
import { print, printError } from "../cli/print.js";
|
|
4
|
+
import { ANSI_YELLOW } from "../cli/ansiColors.js";
|
|
5
|
+
import { getScaffoldDirectory } from "../config/util.js";
|
|
6
|
+
const USAGE = 'Usage: argot semantics [output.css] [--extended] [--force] [--dry-run]\n';
|
|
7
|
+
function runSemantics(args, config = {}) {
|
|
8
|
+
const { values, positionals } = parseArgs({
|
|
9
|
+
args,
|
|
10
|
+
allowPositionals: true,
|
|
11
|
+
options: {
|
|
12
|
+
force: { type: 'boolean', default: false },
|
|
13
|
+
extended: { type: 'boolean', default: false },
|
|
14
|
+
'dry-run': { type: 'boolean', default: false },
|
|
15
|
+
help: { type: 'boolean', short: 'h', default: false },
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
if (values.help) {
|
|
19
|
+
print(USAGE, ANSI_YELLOW);
|
|
20
|
+
return;
|
|
19
21
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
let extended = false;
|
|
23
|
+
if (config.semantics?.set === 'extended') {
|
|
24
|
+
extended = true;
|
|
25
|
+
}
|
|
26
|
+
if (values.extended) {
|
|
27
|
+
extended = true;
|
|
28
|
+
}
|
|
29
|
+
if (positionals.length > 1) {
|
|
30
|
+
printError('Error: too many arguments');
|
|
31
|
+
print(USAGE, ANSI_YELLOW);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
const output = positionals[0] ??
|
|
35
|
+
config.semantics?.output ??
|
|
36
|
+
`${getScaffoldDirectory(config)}/vars-semantic.css`;
|
|
37
|
+
const result = writeTemplate(output, { extended }, { force: values.force, dryRun: values['dry-run'] });
|
|
38
|
+
print(`${result.written ? 'Wrote' : 'Would write'} ${result.path}`);
|
|
32
39
|
}
|
|
33
40
|
export { runSemantics };
|
|
34
41
|
//# sourceMappingURL=cli.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/semantics/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/semantics/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,C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AC,CAAC,CAAC;QACd,MAAM,CAAC,SAAS,EAAE,MAAM;QACxB,GAAG,oBAAoB,CAAC,MAAM,CAAC,oBAAoB,CAAC;IAEtD,MAAM,MAAM,GAAG,aAAa,CAC1B,MAAM,EACN,EAAE,QAAQ,EAAE,EACZ,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE,CACnD,CAAC;IACF,KAAK,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;AACtE,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { parseArgs } from 'node:util';\nimport { writeTemplate } from './generate.ts';\nimport { print, printError } from '../cli/print.ts';\nimport { ANSI_YELLOW } from '../cli/ansiColors.ts';\nimport { getScaffoldDirectory } from '../config/util.ts';\nimport type { ArgotConfig } from '../config/types.ts';\n\nconst USAGE =\n 'Usage: argot semantics [output.css] [--extended] [--force] [--dry-run]\\n';\n\nfunction runSemantics(args: string[], config: ArgotConfig = {}): void {\n const { values, positionals } = parseArgs({\n args,\n allowPositionals: true,\n options: {\n force: { type: 'boolean', default: false },\n extended: { type: 'boolean', default: false },\n 'dry-run': { type: 'boolean', default: false },\n help: { type: 'boolean', short: 'h', default: false },\n },\n });\n\n if (values.help) {\n print(USAGE, ANSI_YELLOW);\n return;\n }\n\n let extended = false;\n if (config.semantics?.set === 'extended') {\n extended = true;\n }\n\n if (values.extended) {\n extended = true;\n }\n\n if (positionals.length > 1) {\n printError('Error: too many arguments');\n print(USAGE, ANSI_YELLOW);\n process.exit(1);\n }\n\n const output =\n positionals[0] ??\n config.semantics?.output ??\n `${getScaffoldDirectory(config)}/vars-semantic.css`;\n\n const result = writeTemplate(\n output,\n { extended },\n { force: values.force, dryRun: values['dry-run'] },\n );\n print(`${result.written ? 'Wrote' : 'Would write'} ${result.path}`);\n}\n\nexport { runSemantics };\n"]}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
import type { WriteOutputOptions } from '../lib/writeOutput.ts';
|
|
1
2
|
import type { TokenOptions, TokenSection } from './load-tokens.ts';
|
|
2
3
|
export type { TokenOptions, TokenRecord, TokenSection } from './load-tokens.ts';
|
|
4
|
+
export type WriteTemplateOptions = WriteOutputOptions;
|
|
5
|
+
export interface WriteTemplateResult {
|
|
6
|
+
path: string;
|
|
7
|
+
css: string;
|
|
8
|
+
written: boolean;
|
|
9
|
+
}
|
|
3
10
|
/**
|
|
4
11
|
* Write the CSS template to disk.
|
|
5
12
|
*/
|
|
6
|
-
declare function writeTemplate(outPath: string, options?: TokenOptions):
|
|
13
|
+
declare function writeTemplate(outPath: string, options?: TokenOptions, writeOptions?: WriteTemplateOptions): WriteTemplateResult;
|
|
7
14
|
/**
|
|
8
15
|
* Generate CSS text from the package tokens directory.
|
|
9
16
|
* @param {{ extended?: boolean }} [options]
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from 'node:path';
|
|
1
|
+
import { writeOutput } from "../lib/writeOutput.js";
|
|
3
2
|
import { loadTokens } from "./load-tokens.js";
|
|
4
3
|
/**
|
|
5
4
|
* Write the CSS template to disk.
|
|
6
5
|
*/
|
|
7
|
-
function writeTemplate(outPath, options = {}) {
|
|
6
|
+
function writeTemplate(outPath, options = {}, writeOptions = {}) {
|
|
8
7
|
const css = generateCss(options);
|
|
9
|
-
const resolved =
|
|
10
|
-
|
|
11
|
-
fs.writeFileSync(resolved, css, 'utf8');
|
|
12
|
-
return resolved;
|
|
8
|
+
const { path: resolved, written } = writeOutput(outPath, css, writeOptions);
|
|
9
|
+
return { path: resolved, css, written };
|
|
13
10
|
}
|
|
14
11
|
/**
|
|
15
12
|
* Generate CSS text from the package tokens directory.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/semantics/generate.ts"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,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9D,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,MAA8B;IACpD,MAAM,KAAK,GAAG,EAAE,CAAC;IAEjB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAkB;IAC3C,MAAM,KAAK,GACT,KAAK,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS;QACrE,CAAC,CAAC,GAAG;QACL,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;IACxB,OAAO,KAAK,KAAK,CAAC,IAAI,IAAI,KAAK,GAAG,CAAC;AACrC,CAAC;AAED,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import { writeOutput } from '../lib/writeOutput.ts';\nimport type { WriteOutputOptions } from '../lib/writeOutput.ts';\nimport { loadTokens } from './load-tokens.ts';\nimport type { TokenOptions, TokenRecord, TokenSection } from './load-tokens.ts';\n\nexport type { TokenOptions, TokenRecord, TokenSection } from './load-tokens.ts';\n\nexport type WriteTemplateOptions = WriteOutputOptions;\n\nexport interface WriteTemplateResult {\n path: string;\n css: string;\n written: boolean;\n}\n\n/**\n * Write the CSS template to disk.\n */\nfunction writeTemplate(\n outPath: string,\n options: TokenOptions = {},\n writeOptions: WriteTemplateOptions = {},\n): WriteTemplateResult {\n const css = generateCss(options);\n const { path: resolved, written } = writeOutput(outPath, css, writeOptions);\n return { path: resolved, css, written };\n}\n\n/**\n * Generate CSS text from the package tokens directory.\n * @param {{ extended?: boolean }} [options]\n */\nfunction generateCss(options: TokenOptions = {}): string {\n return renderCss(loadTokens(options));\n}\n\n/**\n * Build a :root CSS template from loaded sections.\n */\nfunction renderCss(sections: readonly TokenSection[]): string {\n const blocks = [];\n\n for (const section of sections) {\n const { label, tokens } = section;\n if (tokens.length === 0) continue;\n\n const lines = [` /* ${label} */`];\n lines.push(...formatTokenRun(tokens));\n\n blocks.push(lines.join('\\n'));\n }\n\n return [':root {', blocks.join('\\n\\n'), '}', ''].join('\\n');\n}\n\n/**\n * Emit tokens in source order.\n */\nfunction formatTokenRun(tokens: readonly TokenRecord[]): string[] {\n const lines = [];\n\n for (const token of tokens) {\n lines.push(formatDeclaration(token));\n }\n return lines;\n}\n\nfunction formatDeclaration(token: TokenRecord): string {\n const value =\n token.value === '' || token.value === null || token.value === undefined\n ? ' '\n : ` ${token.value}`;\n return ` ${token.name}:${value};`;\n}\n\nexport { generateCss, renderCss, writeTemplate };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-tokens.js","sourceRoot":"","sources":["../../src/semantics/load-tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAkC7B,uEAAuE;AACvE,MAAM,QAAQ,GAAG;IACf,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,kBAAkB,EAAE;IACpD,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,cAAc,EAAE;IAClD,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAAE,iBAAiB,EAAE;IACvD,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,eAAe,EAAE;IACnD,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,gBAAgB,EAAE;IACrD,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,YAAY,EAAE;IAChD,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE;IAC1C,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,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QAAQ;QACxB,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QACpB,CAAC,QAAQ,IAAI,IAAI,IAAI,OAAO,IAAI,IAAI,CAAC,CACtC,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nexport interface TokenOptions {\n extended?: boolean;\n}\n\nexport interface TokenRecord {\n name: string;\n value: string | null;\n description: string;\n tier: 'core' | 'extended';\n type: string;\n usage: string;\n pairsWith
|
|
1
|
+
{"version":3,"file":"load-tokens.js","sourceRoot":"","sources":["../../src/semantics/load-tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAkC7B,uEAAuE;AACvE,MAAM,QAAQ,GAAG;IACf,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,kBAAkB,EAAE;IACpD,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,cAAc,EAAE;IAClD,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAAE,iBAAiB,EAAE;IACvD,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,eAAe,EAAE;IACnD,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,gBAAgB,EAAE;IACrD,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,YAAY,EAAE;IAChD,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE;IAC1C,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE;IAC1C,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,QAAQ,EAAE;IACxC,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,QAAQ,EAAE;IACxC,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,MAA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,EAAE,CAAC","sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nexport interface TokenOptions {\n extended?: boolean;\n}\n\nexport interface TokenRecord {\n name: string;\n value: string | null;\n description: string;\n tier: 'core' | 'extended';\n type: string;\n usage: string;\n pairsWith?: string[];\n related?: string[];\n}\n\nexport interface TokenSection {\n file: string;\n label: string;\n tokens: TokenRecord[];\n}\n\n/** Packaged DTCG-shaped source records; not a general token interchange format. */\ninterface TokenSource extends Record<string, unknown> {\n $value?: string | null;\n $type?: string;\n $description?: string;\n tier?: string;\n usage?: string;\n pairsWith?: string[];\n related?: string[];\n}\n\n/** Ordered token groups shared by CSS generation and documentation. */\nconst SECTIONS = [\n { file: 'color-bg.json', label: 'color — surfaces' },\n { file: 'color-text.json', label: 'color — text' },\n { file: 'color-border.json', label: 'color — borders' },\n { file: 'color-icon.json', label: 'color — icons' },\n { file: 'color-chart.json', label: 'color — charts' },\n { file: 'typography.json', label: 'typography' },\n { file: 'spacing.json', label: 'spacing' },\n { file: 'borders.json', label: 'borders' },\n { file: 'motion.json', label: 'motion' },\n { file: 'layout.json', label: 'layout' },\n { file: 'misc.json', label: 'misc' },\n];\n\n/**\n * Load all token files into ordered sections of flat token records.\n */\nfunction loadTokens(options: TokenOptions = {}): TokenSection[] {\n const dir = getTokensDir();\n\n return SECTIONS.map(({ file, label }) => {\n const filePath = path.join(dir, file);\n if (!fs.existsSync(filePath)) {\n throw new Error(`Missing token file: ${filePath}`);\n }\n const tokens: TokenRecord[] = [];\n walk(JSON.parse(fs.readFileSync(filePath, 'utf8')), [], tokens);\n return {\n file,\n label,\n tokens: tokens.filter((t) => {\n if (t.tier === 'core') {\n return true;\n }\n if (options.extended) {\n return true;\n }\n return false;\n }),\n };\n });\n}\n\nfunction getTokensDir(packageRoot = path.join(import.meta.dirname, '../..')) {\n return path.join(packageRoot, 'tokens');\n}\n\nfunction walk(node: unknown, parts: string[], out: TokenRecord[]): void {\n if (!node || typeof node !== 'object' || Array.isArray(node)) return;\n if (isToken(node)) {\n out.push({\n name: `--${parts.join('-')}`,\n value: node.$value === undefined || node.$value === '' ? '' : node.$value,\n description: node.$description || '',\n tier: node.tier === 'extended' ? 'extended' : 'core',\n type: node.$type || '',\n usage: node.usage || '',\n pairsWith: node.pairsWith || [],\n related: node.related || [],\n });\n return;\n }\n for (const [key, child] of Object.entries(node)) {\n walk(child, parts.concat(key), out);\n }\n}\n\nfunction isToken(node: unknown): node is TokenSource {\n return (\n node !== null &&\n typeof node === 'object' &&\n !Array.isArray(node) &&\n ('$value' in node || '$type' in node)\n );\n}\n\nexport { SECTIONS, loadTokens, getTokensDir };\n"]}
|
package/dist/stylelint/config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { colorContrast } from "./index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Shareable Stylelint config for Argot token usage.
|
|
4
4
|
*
|
|
@@ -9,11 +9,9 @@ import { fileURLToPath } from 'node:url';
|
|
|
9
9
|
* };
|
|
10
10
|
*/
|
|
11
11
|
export default {
|
|
12
|
-
plugins: [
|
|
13
|
-
fileURLToPath(new URL(import.meta.url.endsWith('.ts') ? './index.ts' : './index.js', import.meta.url)),
|
|
14
|
-
],
|
|
12
|
+
plugins: [colorContrast],
|
|
15
13
|
rules: {
|
|
16
|
-
'argot/
|
|
14
|
+
'argot/color-contrast': true,
|
|
17
15
|
},
|
|
18
16
|
};
|
|
19
17
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/stylelint/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/stylelint/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;GAQG;AACH,eAAe;IACb,OAAO,EAAE,CAAC,aAAa,CAAC;IACxB,KAAK,EAAE;QACL,sBAAsB,EAAE,IAAI;KAC7B;CACe,CAAC","sourcesContent":["import type { Config } from 'stylelint';\nimport { colorContrast } from './index.ts';\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: [colorContrast],\n rules: {\n 'argot/color-contrast': true,\n },\n} satisfies Config;\n"]}
|
package/dist/stylelint/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stylelint/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stylelint/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,0BAA0B,CAAC;AAErD,0CAA0C;AAC1C,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import colorContrast from './rules/colorContrast.ts';\n\n/** Stylelint plugins shipped by Argot. */\nexport { colorContrast };\n"]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import stylelint from 'stylelint';
|
|
2
|
+
import Color from 'colorjs.io';
|
|
3
|
+
import { isCustomPropertyDeclaration, isColorPrimitive, getToken, resolveColor, } from "./util.js";
|
|
4
|
+
import { loadTokens } from "../../semantics/load-tokens.js";
|
|
5
|
+
export const ruleName = 'argot/color-contrast';
|
|
6
|
+
const AA_CONTRAST = 4.5;
|
|
7
|
+
const ruleMessages = stylelint.utils.ruleMessages(ruleName, {
|
|
8
|
+
unexpected: (name, prop) => `Foreground property "${prop}" has insufficient contrast with x".`,
|
|
9
|
+
});
|
|
10
|
+
const ruleFunction = () => {
|
|
11
|
+
const tokens = loadTokens();
|
|
12
|
+
return async (root, result) => {
|
|
13
|
+
const primitives = {};
|
|
14
|
+
const semantics = {};
|
|
15
|
+
const semanticDecls = {};
|
|
16
|
+
root.walkDecls((decl) => {
|
|
17
|
+
if (!isCustomPropertyDeclaration(decl)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (isColorPrimitive(decl.prop, decl.value)) {
|
|
21
|
+
primitives[decl.prop] = decl.value;
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const token = getToken(decl.prop, tokens);
|
|
25
|
+
if (!token) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const colorString = resolveColor(decl.value, primitives, semantics);
|
|
29
|
+
semantics[decl.prop] = colorString || 'unknown';
|
|
30
|
+
semanticDecls[decl.prop] = decl;
|
|
31
|
+
});
|
|
32
|
+
const reportedPairs = new Set();
|
|
33
|
+
for (const [name, colorString] of Object.entries(semantics)) {
|
|
34
|
+
if (!colorString || colorString == 'unknown')
|
|
35
|
+
continue;
|
|
36
|
+
const token = getToken(name, tokens);
|
|
37
|
+
if (!token?.pairsWith?.length)
|
|
38
|
+
continue;
|
|
39
|
+
const decl = semanticDecls[name];
|
|
40
|
+
if (!decl)
|
|
41
|
+
continue;
|
|
42
|
+
for (const pair of token.pairsWith) {
|
|
43
|
+
const pairName = `--${pair}`;
|
|
44
|
+
const pairKey = [name, pairName].sort().join('\0');
|
|
45
|
+
if (reportedPairs.has(pairKey))
|
|
46
|
+
continue;
|
|
47
|
+
const pairColor = semantics[pairName];
|
|
48
|
+
if (!pairColor || pairColor === 'unknown')
|
|
49
|
+
continue;
|
|
50
|
+
const pairDecl = semanticDecls[pairName];
|
|
51
|
+
if (!pairDecl)
|
|
52
|
+
continue;
|
|
53
|
+
reportedPairs.add(pairKey);
|
|
54
|
+
let contrast;
|
|
55
|
+
try {
|
|
56
|
+
contrast = new Color(colorString).contrastWCAG21(new Color(pairColor));
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
if (err instanceof TypeError) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
if (contrast >= AA_CONTRAST)
|
|
65
|
+
continue;
|
|
66
|
+
const rounded = contrast.toFixed(2);
|
|
67
|
+
const message = `"${name}" and "${pairName}" have an insufficient contrast ratio of ${rounded}:1 (goal: ${AA_CONTRAST}:1)`;
|
|
68
|
+
const message2 = `"${pairName}" and "${name}" have an insufficient contrast ratio of ${rounded}:1 (goal: ${AA_CONTRAST}:1)`;
|
|
69
|
+
stylelint.utils.report({
|
|
70
|
+
ruleName,
|
|
71
|
+
result,
|
|
72
|
+
message,
|
|
73
|
+
node: decl,
|
|
74
|
+
});
|
|
75
|
+
stylelint.utils.report({
|
|
76
|
+
ruleName,
|
|
77
|
+
result,
|
|
78
|
+
message: message2,
|
|
79
|
+
node: pairDecl,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
ruleFunction.ruleName = ruleName;
|
|
86
|
+
ruleFunction.messages = ruleMessages;
|
|
87
|
+
ruleFunction.meta = {
|
|
88
|
+
url: 'https://github.com/keithjgrant/argot/blob/main/README.md',
|
|
89
|
+
};
|
|
90
|
+
export default stylelint.createPlugin(ruleName, ruleFunction);
|
|
91
|
+
//# sourceMappingURL=colorContrast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colorContrast.js","sourceRoot":"","sources":["../../../src/stylelint/rules/colorContrast.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,OAAO,EACL,2BAA2B,EAC3B,gBAAgB,EAChB,QAAQ,EACR,YAAY,GAGb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D,MAAM,CAAC,MAAM,QAAQ,GAAG,sBAAsB,CAAC;AAE/C,MAAM,WAAW,GAAG,GAAG,CAAC;AAOxB,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,EAAE;IAC1D,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI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QAAQ,4CAA4C,OAAO,aAAa,WAAW,KAAK,CAAC;gBAC3H,MAAM,QAAQ,GAAG,IAAI,QAAQ,UAAU,IAAI,4CAA4C,OAAO,aAAa,WAAW,KAAK,CAAC;gBAE5H,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC;oBACrB,QAAQ;oBACR,MAAM;oBACN,OAAO;oBACP,IAAI,EAAE,IAAI;iBACX,CAAC,CAAC;gBACH,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC;oBACrB,QAAQ;oBACR,MAAM;oBACN,OAAO,EAAE,QAAQ;oBACjB,IAAI,EAAE,QAAQ;iBACf,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,YAAY,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACjC,YAAY,CAAC,QAAQ,GAAG,YAAY,CAAC;AACrC,YAAY,CAAC,IAAI,GAAG;IAClB,GAAG,EAAE,0DAA0D;CAChE,CAAC;AAEF,eAAe,SAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC","sourcesContent":["import stylelint from 'stylelint';\nimport Color from 'colorjs.io';\nimport type { Declaration } from 'postcss';\nimport {\n isCustomPropertyDeclaration,\n isColorPrimitive,\n getToken,\n resolveColor,\n type PrimitiveValues,\n type Semantics,\n} from './util.ts';\nimport { loadTokens } from '../../semantics/load-tokens.ts';\n\nexport const ruleName = 'argot/color-contrast';\n\nconst AA_CONTRAST = 4.5;\n// const AAA_CONTRAST = 7;\n\ninterface SemanticDeclarations {\n [key: string]: Declaration;\n}\n\nconst ruleMessages = stylelint.utils.ruleMessages(ruleName, {\n unexpected: (name, prop) =>\n `Foreground property \"${prop}\" has insufficient contrast with x\".`,\n});\n\nconst ruleFunction: stylelint.Rule = () => {\n const tokens = loadTokens();\n\n return async (root, result) => {\n const primitives: PrimitiveValues = {};\n const semantics: Semantics = {};\n const semanticDecls: SemanticDeclarations = {};\n\n root.walkDecls((decl) => {\n if (!isCustomPropertyDeclaration(decl)) {\n return;\n }\n\n if (isColorPrimitive(decl.prop, decl.value)) {\n primitives[decl.prop] = decl.value;\n return;\n }\n\n const token = getToken(decl.prop, tokens);\n if (!token) {\n return;\n }\n\n const colorString = resolveColor(decl.value, primitives, semantics);\n semantics[decl.prop] = colorString || 'unknown';\n semanticDecls[decl.prop] = decl;\n });\n\n const reportedPairs = new Set<string>();\n\n for (const [name, colorString] of Object.entries(semantics)) {\n if (!colorString || colorString == 'unknown') continue;\n\n const token = getToken(name, tokens);\n if (!token?.pairsWith?.length) continue;\n\n const decl = semanticDecls[name];\n if (!decl) continue;\n\n for (const pair of token.pairsWith) {\n const pairName = `--${pair}`;\n const pairKey = [name, pairName].sort().join('\\0');\n if (reportedPairs.has(pairKey)) continue;\n\n const pairColor = semantics[pairName];\n if (!pairColor || pairColor === 'unknown') continue;\n\n const pairDecl = semanticDecls[pairName];\n if (!pairDecl) continue;\n\n reportedPairs.add(pairKey);\n\n let contrast;\n try {\n contrast = new Color(colorString).contrastWCAG21(\n new Color(pairColor),\n );\n } catch (err) {\n if (err instanceof TypeError) {\n continue;\n }\n throw err;\n }\n if (contrast >= AA_CONTRAST) continue;\n const rounded = contrast.toFixed(2);\n\n const message = `\"${name}\" and \"${pairName}\" have an insufficient contrast ratio of ${rounded}:1 (goal: ${AA_CONTRAST}:1)`;\n const message2 = `\"${pairName}\" and \"${name}\" have an insufficient contrast ratio of ${rounded}:1 (goal: ${AA_CONTRAST}:1)`;\n\n stylelint.utils.report({\n ruleName,\n result,\n message,\n node: decl,\n });\n stylelint.utils.report({\n ruleName,\n result,\n message: message2,\n node: pairDecl,\n });\n }\n }\n };\n};\n\nruleFunction.ruleName = ruleName;\nruleFunction.messages = ruleMessages;\nruleFunction.meta = {\n url: 'https://github.com/keithjgrant/argot/blob/main/README.md',\n};\n\nexport default stylelint.createPlugin(ruleName, ruleFunction);\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ChildNode, Declaration } from 'postcss';
|
|
2
|
+
import type { TokenSection } from '../../semantics/load-tokens.ts';
|
|
3
|
+
export interface PrimitiveValues {
|
|
4
|
+
[key: string]: string;
|
|
5
|
+
}
|
|
6
|
+
export interface Semantics {
|
|
7
|
+
[key: string]: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function isCustomPropertyDeclaration(rule: ChildNode): rule is Declaration;
|
|
10
|
+
export declare function isColorPrimitive(prop: string, value: string): boolean;
|
|
11
|
+
export declare function isColor(value: string): boolean;
|
|
12
|
+
export declare function getToken(name: string, tokens: TokenSection[]): import("../../semantics/load-tokens.ts").TokenRecord | null;
|
|
13
|
+
export declare function resolveColor(value: string, primitives: PrimitiveValues, semantics: Semantics): string | undefined;
|