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
package/dist/palette/types.d.ts
CHANGED
|
@@ -1,40 +1,47 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
export type
|
|
1
|
+
export declare const LightnessCurve: {
|
|
2
|
+
UNIFORM: string;
|
|
3
|
+
INCLUSIVE: string;
|
|
4
|
+
CENTERED: string;
|
|
5
|
+
};
|
|
6
|
+
export type LightnessCurveEnum = (typeof LightnessCurve)[keyof typeof LightnessCurve];
|
|
7
|
+
export declare const ChromaCurve: {
|
|
8
|
+
CENTERED: string;
|
|
9
|
+
WEIGHTED: string;
|
|
10
|
+
};
|
|
11
|
+
export type ChromaCurveEnum = (typeof ChromaCurve)[keyof typeof ChromaCurve];
|
|
12
|
+
export declare const ColorFormat: {
|
|
13
|
+
HEX: string;
|
|
14
|
+
RGB: string;
|
|
15
|
+
HSL: string;
|
|
16
|
+
HWB: string;
|
|
17
|
+
OKLCH: string;
|
|
18
|
+
OKLAB: string;
|
|
19
|
+
LCH: string;
|
|
20
|
+
LAB: string;
|
|
21
|
+
};
|
|
22
|
+
export type ColorFormatEnum = (typeof ColorFormat)[keyof typeof ColorFormat];
|
|
12
23
|
export interface OklchColor {
|
|
13
24
|
/** Lightness from 0 to 1 */
|
|
14
25
|
l: number;
|
|
15
|
-
/** Chroma */
|
|
16
26
|
c: number;
|
|
17
|
-
/** Hue angle in degrees; stored without wrapping or rounding. */
|
|
18
27
|
h: number;
|
|
19
28
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
name?: string;
|
|
29
|
+
export interface NormalizedSeedColor extends OklchColor {
|
|
30
|
+
name: string;
|
|
23
31
|
}
|
|
24
|
-
export type NormalizedSeedColor = Required<SeedColor>;
|
|
25
32
|
export interface PaletteStep extends OklchColor {
|
|
26
33
|
/** One-based index, from 1 through 16. */
|
|
27
34
|
step: number;
|
|
28
35
|
}
|
|
29
|
-
export interface
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
export interface PaletteOptions {
|
|
37
|
+
lightnessCurve: LightnessCurveEnum;
|
|
38
|
+
chromaCurve: ChromaCurveEnum;
|
|
39
|
+
format: ColorFormatEnum;
|
|
33
40
|
}
|
|
34
41
|
export interface NormalizedPaletteDefinition {
|
|
35
42
|
version: 1;
|
|
36
43
|
seedColors: NormalizedSeedColor[];
|
|
37
|
-
options:
|
|
44
|
+
options: PaletteOptions;
|
|
38
45
|
}
|
|
39
46
|
export interface PaletteScale {
|
|
40
47
|
name: string;
|
|
@@ -46,5 +53,5 @@ export interface PaletteScale {
|
|
|
46
53
|
export interface Palette {
|
|
47
54
|
version: 1;
|
|
48
55
|
colors: PaletteScale[];
|
|
49
|
-
options:
|
|
56
|
+
options: PaletteOptions;
|
|
50
57
|
}
|
package/dist/palette/types.js
CHANGED
|
@@ -1,2 +1,27 @@
|
|
|
1
|
-
export
|
|
1
|
+
// export type ColorGamut = 'p3' | 'srgb';
|
|
2
|
+
/*
|
|
3
|
+
* Seed - input color (and optional name) to generate steps
|
|
4
|
+
* Step - tint/shade of a certain hue
|
|
5
|
+
* Scale - set of 16 steps
|
|
6
|
+
* Palette - full set of colors
|
|
7
|
+
*/
|
|
8
|
+
export const LightnessCurve = {
|
|
9
|
+
UNIFORM: 'uniform',
|
|
10
|
+
INCLUSIVE: 'inclusive',
|
|
11
|
+
CENTERED: 'centered',
|
|
12
|
+
};
|
|
13
|
+
export const ChromaCurve = {
|
|
14
|
+
CENTERED: 'centered',
|
|
15
|
+
WEIGHTED: 'weighted',
|
|
16
|
+
};
|
|
17
|
+
export const ColorFormat = {
|
|
18
|
+
HEX: 'hex',
|
|
19
|
+
RGB: 'rgb',
|
|
20
|
+
HSL: 'hsl',
|
|
21
|
+
HWB: 'hwb',
|
|
22
|
+
OKLCH: 'oklch',
|
|
23
|
+
OKLAB: 'oklab',
|
|
24
|
+
LCH: 'lch',
|
|
25
|
+
LAB: 'lab',
|
|
26
|
+
};
|
|
2
27
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/palette/types.ts"],"names":[],"mappings":"","sourcesContent":["export type
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/palette/types.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAE1C;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;CACrB,CAAC;AAIF,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;CACrB,CAAC;AAGF,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;CACX,CAAC","sourcesContent":["// export type ColorGamut = 'p3' | 'srgb';\n\n/*\n * Seed - input color (and optional name) to generate steps\n * Step - tint/shade of a certain hue\n * Scale - set of 16 steps\n * Palette - full set of colors\n */\n\nexport const LightnessCurve = {\n UNIFORM: 'uniform',\n INCLUSIVE: 'inclusive',\n CENTERED: 'centered',\n};\nexport type LightnessCurveEnum =\n (typeof LightnessCurve)[keyof typeof LightnessCurve];\n\nexport const ChromaCurve = {\n CENTERED: 'centered',\n WEIGHTED: 'weighted',\n};\nexport type ChromaCurveEnum = (typeof ChromaCurve)[keyof typeof ChromaCurve];\n\nexport const ColorFormat = {\n HEX: 'hex',\n RGB: 'rgb',\n HSL: 'hsl',\n HWB: 'hwb',\n OKLCH: 'oklch',\n OKLAB: 'oklab',\n LCH: 'lch',\n LAB: 'lab',\n};\nexport type ColorFormatEnum = (typeof ColorFormat)[keyof typeof ColorFormat];\n\nexport interface OklchColor {\n /** Lightness from 0 to 1 */\n l: number;\n c: number;\n h: number;\n}\n\nexport interface NormalizedSeedColor extends OklchColor {\n name: string;\n}\n\nexport interface PaletteStep extends OklchColor {\n /** One-based index, from 1 through 16. */\n step: number;\n}\n\nexport interface PaletteOptions {\n lightnessCurve: LightnessCurveEnum;\n chromaCurve: ChromaCurveEnum;\n format: ColorFormatEnum;\n}\n\n// Palette definition with all options filled in\nexport interface NormalizedPaletteDefinition {\n version: 1;\n seedColors: NormalizedSeedColor[];\n options: PaletteOptions;\n}\n\n// TODO: can baseStep be removed?\n// don't need to output it to CSS any longer, but might need to\n// indicate to user where seedColor landed in the set\nexport interface PaletteScale {\n name: string;\n /** One-based step used for the unnumbered custom-property alias. */\n baseStep: number;\n steps: PaletteStep[];\n}\n\n/** Raw OKLCH coordinates, before output gamut mapping or rounding. */\nexport interface Palette {\n version: 1;\n colors: PaletteScale[];\n options: PaletteOptions;\n}\n"]}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type NormalizedPaletteDefinition, type PaletteOptions, type OklchColor } from './types.ts';
|
|
2
2
|
/**
|
|
3
|
-
* Validate a
|
|
3
|
+
* Validate a palette definition and return a "normalized" fresh copy with
|
|
4
|
+
* explicit defaults set.
|
|
4
5
|
* Color names must also be unique across all emitted step names and aliases.
|
|
5
6
|
*/
|
|
6
7
|
declare function normalizePaletteDefinition(definition: unknown): NormalizedPaletteDefinition;
|
|
7
|
-
declare function normalizeOptions(options?: unknown):
|
|
8
|
+
declare function normalizeOptions(options?: unknown): PaletteOptions;
|
|
8
9
|
declare function checkName(name: unknown, field: string): asserts name is string;
|
|
9
10
|
/** Validate numeric seeds without conversion, wrapping, clamping, or rounding. */
|
|
10
11
|
declare function checkCoordinates(value: Record<string, unknown>, field: string): asserts value is Record<string, unknown> & OklchColor;
|
|
11
|
-
|
|
12
|
-
declare function serializePaletteDefinition(definition: PaletteDefinition): string;
|
|
13
|
-
export { normalizePaletteDefinition, serializePaletteDefinition, normalizeOptions, checkName, checkCoordinates, };
|
|
12
|
+
export { normalizePaletteDefinition, normalizeOptions, checkName, checkCoordinates, };
|
|
@@ -1,85 +1,101 @@
|
|
|
1
|
-
import { generateName, dedupeNames } from "./generateName.js";
|
|
1
|
+
import { generateName, dedupeNames as dedupeSeedNames, } from "./generateName.js";
|
|
2
|
+
import { LightnessCurve, ChromaCurve, ColorFormat, } from "./types.js";
|
|
3
|
+
import Color from 'colorjs.io';
|
|
2
4
|
const OPTION_VALUES = {
|
|
3
|
-
lightnessCurve:
|
|
4
|
-
chromaCurve:
|
|
5
|
-
format:
|
|
6
|
-
gamut: ['p3', 'srgb'],
|
|
5
|
+
lightnessCurve: Object.values(LightnessCurve),
|
|
6
|
+
chromaCurve: Object.values(ChromaCurve),
|
|
7
|
+
format: Object.values(ColorFormat),
|
|
7
8
|
};
|
|
8
9
|
/**
|
|
9
|
-
* Validate a
|
|
10
|
+
* Validate a palette definition and return a "normalized" fresh copy with
|
|
11
|
+
* explicit defaults set.
|
|
10
12
|
* Color names must also be unique across all emitted step names and aliases.
|
|
11
13
|
*/
|
|
12
14
|
function normalizePaletteDefinition(definition) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
checkObjectKeys(definition, 'definition', [
|
|
16
|
+
'version',
|
|
17
|
+
'seedColors',
|
|
18
|
+
'lightnessCurve',
|
|
19
|
+
'chromaCurve',
|
|
20
|
+
'format',
|
|
21
|
+
]);
|
|
22
|
+
if (definition.version && definition.version !== 1) {
|
|
15
23
|
throw new Error('definition.version: expected supported version 1');
|
|
16
24
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
throw new Error('definition.seedColors: expected
|
|
25
|
+
const seedColors = definition.seedColors ?? [];
|
|
26
|
+
if (!Array.isArray(seedColors)) {
|
|
27
|
+
throw new Error('definition.seedColors: expected an array');
|
|
20
28
|
}
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const colors = Array.from(entries, (entry, index) => {
|
|
24
|
-
const field = `definition.seedColors[${index}]`;
|
|
25
|
-
checkObject(entry, field, ['name', 'l', 'c', 'h']);
|
|
26
|
-
checkCoordinates(entry, field);
|
|
27
|
-
if (!entry.name) {
|
|
28
|
-
entry.name = generateName(entry);
|
|
29
|
-
// throw new Error('name ' + entry.name);
|
|
30
|
-
}
|
|
31
|
-
checkName(entry.name, `${field}.name`);
|
|
32
|
-
// for (const name of [
|
|
33
|
-
// entry.name,
|
|
34
|
-
// ...Array.from({ length: 16 }, (_, i) => `${entry.name}-${i + 1}`),
|
|
35
|
-
// ]) {
|
|
36
|
-
// if (names.has(name)) {
|
|
37
|
-
// throw new Error(`${field}.name: duplicate custom property "--${name}"`);
|
|
38
|
-
// }
|
|
39
|
-
// names.add(name);
|
|
40
|
-
// }
|
|
41
|
-
return { name: entry.name, l: entry.l, c: entry.c, h: entry.h };
|
|
42
|
-
});
|
|
29
|
+
const entries = seedColors;
|
|
30
|
+
const colors = Array.from(entries, normalizeSeedColor);
|
|
43
31
|
return {
|
|
44
32
|
version: 1,
|
|
45
|
-
seedColors:
|
|
46
|
-
options: normalizeOptions(definition
|
|
33
|
+
seedColors: dedupeSeedNames(colors),
|
|
34
|
+
options: normalizeOptions(definition),
|
|
47
35
|
};
|
|
48
36
|
}
|
|
37
|
+
function normalizeSeedColor(entry, index) {
|
|
38
|
+
{
|
|
39
|
+
const fieldName = `definition.seedColors[${index}]`;
|
|
40
|
+
let colorStr;
|
|
41
|
+
let name = '';
|
|
42
|
+
if (typeof entry === 'string') {
|
|
43
|
+
colorStr = entry;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
checkObjectKeys(entry, fieldName, ['name', 'color']);
|
|
47
|
+
colorStr = entry.color;
|
|
48
|
+
name = entry.name;
|
|
49
|
+
}
|
|
50
|
+
let parsed;
|
|
51
|
+
try {
|
|
52
|
+
parsed = new Color(colorStr.trim()).to('oklch');
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
throw new Error(`${fieldName}.color: expected a CSS color (${error instanceof Error ? error.message : String(error)})`, { cause: error });
|
|
56
|
+
}
|
|
57
|
+
const [l, c, h] = parsed.coords;
|
|
58
|
+
const coords = { l, c, h };
|
|
59
|
+
checkCoordinates(coords, fieldName);
|
|
60
|
+
const seed = {
|
|
61
|
+
name,
|
|
62
|
+
...coords,
|
|
63
|
+
};
|
|
64
|
+
if (!name) {
|
|
65
|
+
seed.name = generateName(seed);
|
|
66
|
+
}
|
|
67
|
+
checkName(seed.name, `${fieldName}.name`);
|
|
68
|
+
return seed;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
49
71
|
function normalizeOptions(options = {}) {
|
|
50
|
-
|
|
51
|
-
const supplied = options;
|
|
72
|
+
const supplied = options || {};
|
|
52
73
|
function option(key, fallback) {
|
|
53
74
|
const value = Object.hasOwn(supplied, key) ? supplied[key] : fallback;
|
|
54
75
|
const values = OPTION_VALUES[key];
|
|
55
76
|
if (!values.some((candidate) => candidate === value)) {
|
|
56
|
-
throw new Error(`
|
|
77
|
+
throw new Error(`palette.${key}: expected one of ${values.join(', ')}`);
|
|
57
78
|
}
|
|
58
|
-
// Runtime membership validation above establishes the public option union.
|
|
59
79
|
return value;
|
|
60
80
|
}
|
|
61
81
|
const result = {
|
|
62
|
-
lightnessCurve: option('lightnessCurve',
|
|
63
|
-
chromaCurve: option('chromaCurve',
|
|
64
|
-
format: option('format',
|
|
65
|
-
gamut: 'p3',
|
|
82
|
+
lightnessCurve: option('lightnessCurve', LightnessCurve.UNIFORM),
|
|
83
|
+
chromaCurve: option('chromaCurve', ChromaCurve.CENTERED),
|
|
84
|
+
format: option('format', ColorFormat.OKLCH),
|
|
66
85
|
};
|
|
67
|
-
result.gamut = option('gamut', result.format === 'hex' ? 'srgb' : 'p3');
|
|
68
|
-
if (result.format === 'hex' && result.gamut !== 'srgb') {
|
|
69
|
-
throw new Error('definition.options.gamut: hex output requires srgb');
|
|
70
|
-
}
|
|
71
86
|
return result;
|
|
72
87
|
}
|
|
73
|
-
|
|
88
|
+
/* Asserts `value` is an object with no unknown/unexpected keys */
|
|
89
|
+
function checkObjectKeys(value, fieldName, validKeys) {
|
|
74
90
|
if (value === null ||
|
|
75
91
|
typeof value !== 'object' ||
|
|
76
92
|
Array.isArray(value) ||
|
|
77
93
|
![Object.prototype, null].includes(Object.getPrototypeOf(value))) {
|
|
78
|
-
throw new Error(`${
|
|
94
|
+
throw new Error(`${fieldName}: expected a plain object`);
|
|
79
95
|
}
|
|
80
96
|
for (const key of Object.keys(value)) {
|
|
81
|
-
if (!
|
|
82
|
-
throw new Error(`${
|
|
97
|
+
if (!validKeys.includes(key)) {
|
|
98
|
+
throw new Error(`${fieldName}.${key}: unknown field`);
|
|
83
99
|
}
|
|
84
100
|
}
|
|
85
101
|
}
|
|
@@ -102,9 +118,5 @@ function checkCoordinates(value, field) {
|
|
|
102
118
|
throw new Error(`${field}.h: expected a finite hue angle in degrees`);
|
|
103
119
|
}
|
|
104
120
|
}
|
|
105
|
-
|
|
106
|
-
function serializePaletteDefinition(definition) {
|
|
107
|
-
return `${JSON.stringify(normalizePaletteDefinition(definition), null, 2)}\n`;
|
|
108
|
-
}
|
|
109
|
-
export { normalizePaletteDefinition, serializePaletteDefinition, normalizeOptions, checkName, checkCoordinates, };
|
|
121
|
+
export { normalizePaletteDefinition, normalizeOptions, checkName, checkCoordinates, };
|
|
110
122
|
//# sourceMappingURL=validation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/palette/validation.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/palette/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,WAAW,IAAI,eAAe,GA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A0B,EAC1B,gBAAgB,EAChB,SAAS,EACT,gBAAgB,GACjB,CAAC","sourcesContent":["import {\n generateName,\n dedupeNames as dedupeSeedNames,\n} from './generateName.ts';\nimport {\n type NormalizedPaletteDefinition,\n type PaletteOptions,\n type NormalizedSeedColor,\n type OklchColor,\n LightnessCurve,\n ChromaCurve,\n ColorFormat,\n} from './types.ts';\nimport Color from 'colorjs.io';\n\nconst OPTION_VALUES = {\n lightnessCurve: Object.values(LightnessCurve),\n chromaCurve: Object.values(ChromaCurve),\n format: Object.values(ColorFormat),\n} as const;\n\n/**\n * Validate a palette definition and return a \"normalized\" fresh copy with\n * explicit defaults set.\n * Color names must also be unique across all emitted step names and aliases.\n */\nfunction normalizePaletteDefinition(\n definition: unknown,\n): NormalizedPaletteDefinition {\n checkObjectKeys(definition, 'definition', [\n 'version',\n 'seedColors',\n 'lightnessCurve',\n 'chromaCurve',\n 'format',\n ]);\n\n if (definition.version && definition.version !== 1) {\n throw new Error('definition.version: expected supported version 1');\n }\n\n const seedColors = definition.seedColors ?? [];\n\n if (!Array.isArray(seedColors)) {\n throw new Error('definition.seedColors: expected an array');\n }\n\n const entries: unknown[] = seedColors as unknown[];\n const colors = Array.from(entries, normalizeSeedColor);\n\n return {\n version: 1,\n seedColors: dedupeSeedNames(colors),\n options: normalizeOptions(definition),\n };\n}\n\nfunction normalizeSeedColor(entry: unknown, index: number) {\n {\n const fieldName = `definition.seedColors[${index}]`;\n\n let colorStr: string;\n let name: string = '';\n if (typeof entry === 'string') {\n colorStr = entry;\n } else {\n checkObjectKeys(entry, fieldName, ['name', 'color']);\n colorStr = entry.color as string;\n name = entry.name as string;\n }\n\n let parsed;\n try {\n parsed = new Color(colorStr.trim()).to('oklch');\n } catch (error) {\n throw new Error(\n `${fieldName}.color: expected a CSS color (${error instanceof Error ? error.message : String(error)})`,\n { cause: error },\n );\n }\n\n const [l, c, h] = parsed.coords;\n const coords = { l, c, h };\n checkCoordinates(coords, fieldName);\n\n const seed: NormalizedSeedColor = {\n name,\n ...coords,\n };\n\n if (!name) {\n seed.name = generateName(seed);\n }\n checkName(seed.name, `${fieldName}.name`);\n\n return seed;\n }\n}\n\nfunction normalizeOptions(options: unknown = {}): PaletteOptions {\n const supplied: Partial<PaletteOptions> = options || {};\n\n function option<K extends keyof PaletteOptions>(\n key: K,\n fallback: PaletteOptions[K],\n ): PaletteOptions[K] {\n const value = Object.hasOwn(supplied, key) ? supplied[key] : fallback;\n const values = OPTION_VALUES[key];\n\n if (!values.some((candidate) => candidate === value)) {\n throw new Error(`palette.${key}: expected one of ${values.join(', ')}`);\n }\n\n return value as PaletteOptions[K];\n }\n\n const result: PaletteOptions = {\n lightnessCurve: option('lightnessCurve', LightnessCurve.UNIFORM),\n chromaCurve: option('chromaCurve', ChromaCurve.CENTERED),\n format: option('format', ColorFormat.OKLCH),\n };\n return result;\n}\n\n/* Asserts `value` is an object with no unknown/unexpected keys */\nfunction checkObjectKeys(\n value: unknown,\n fieldName: string,\n validKeys: readonly string[],\n): asserts value is Record<string, unknown> {\n if (\n value === null ||\n typeof value !== 'object' ||\n Array.isArray(value) ||\n ![Object.prototype, null].includes(Object.getPrototypeOf(value))\n ) {\n throw new Error(`${fieldName}: expected a plain object`);\n }\n\n for (const key of Object.keys(value)) {\n if (!validKeys.includes(key)) {\n throw new Error(`${fieldName}.${key}: unknown field`);\n }\n }\n}\n\nfunction checkName(name: unknown, field: string): asserts name is string {\n if (\n typeof name !== 'string' ||\n !/^[a-zA-Z][a-zA-Z0-9]*(?:-[a-zA-Z0-9]+)*$/.test(name)\n ) {\n throw new Error(\n `${field}: expected an alphanumeric name such as \"blue\" or \"BrandPrimary\"`,\n );\n }\n}\n\n/** Validate numeric seeds without conversion, wrapping, clamping, or rounding. */\nfunction checkCoordinates(\n value: Record<string, unknown>,\n field: string,\n): asserts value is Record<string, unknown> & OklchColor {\n const { l, c, h } = value;\n if (typeof l !== 'number' || !Number.isFinite(l) || l < 0 || l > 1) {\n throw new Error(`${field}.l: expected finite lightness between 0 and 1`);\n }\n if (typeof c !== 'number' || !Number.isFinite(c) || c < 0) {\n throw new Error(`${field}.c: expected finite, nonnegative chroma`);\n }\n if (typeof h !== 'number' || !Number.isFinite(h)) {\n throw new Error(`${field}.h: expected a finite hue angle in degrees`);\n }\n}\n\nexport {\n normalizePaletteDefinition,\n normalizeOptions,\n checkName,\n checkCoordinates,\n};\n"]}
|
package/dist/processor/cli.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ArgotConfig } from '../config/types.ts';
|
|
2
|
+
export declare function runProcessor(args: string[], config?: ArgotConfig): Promise<void>;
|
package/dist/processor/cli.js
CHANGED
|
@@ -3,9 +3,10 @@ import { parseArgs } from 'node:util';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { processStylesheet } from "./index.js";
|
|
5
5
|
import { print, printError } from "../cli/print.js";
|
|
6
|
+
import {} from "../config/types.js";
|
|
6
7
|
import { ANSI_YELLOW } from "../cli/ansiColors.js";
|
|
7
|
-
const USAGE = 'Usage: argot <input.css> <output.css> [--lint-config="path/to/config.js"]';
|
|
8
|
-
export async function runProcessor(args) {
|
|
8
|
+
const USAGE = 'Usage: argot <input.css> <output.css> [--lint-config="path/to/config.js"]\n';
|
|
9
|
+
export async function runProcessor(args, config = {}) {
|
|
9
10
|
// TODO: helper for parseArgs. catches TypeError and prints help string
|
|
10
11
|
const { positionals, values } = parseArgs({
|
|
11
12
|
args,
|
|
@@ -16,17 +17,29 @@ export async function runProcessor(args) {
|
|
|
16
17
|
verbose: { type: 'boolean' },
|
|
17
18
|
},
|
|
18
19
|
});
|
|
19
|
-
if (
|
|
20
|
-
|
|
20
|
+
if (!config.processor) {
|
|
21
|
+
config.processor = {};
|
|
22
|
+
}
|
|
23
|
+
if (positionals.length === 2) {
|
|
24
|
+
config.processor.source = positionals[0];
|
|
25
|
+
config.processor.destination = positionals[1];
|
|
26
|
+
}
|
|
27
|
+
if (!config.processor.source || !config.processor.destination) {
|
|
28
|
+
printError(`Error: cssSource and cssDest must both be provided`);
|
|
21
29
|
print(USAGE, ANSI_YELLOW);
|
|
22
30
|
return;
|
|
23
31
|
}
|
|
24
32
|
if (values.help) {
|
|
25
33
|
print(USAGE, ANSI_YELLOW);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (values['lint-config']) {
|
|
37
|
+
config.processor.lintConfig = values['lint-config'];
|
|
26
38
|
}
|
|
27
|
-
|
|
28
|
-
const
|
|
39
|
+
// TODO: resolve path relative to config file if not from positionals
|
|
40
|
+
const source = path.resolve(process.cwd(), config.processor.source);
|
|
41
|
+
const dest = path.resolve(process.cwd(), config.processor.destination);
|
|
29
42
|
await fs.mkdir(path.dirname(dest), { recursive: true });
|
|
30
|
-
return await processStylesheet(source, dest,
|
|
43
|
+
return await processStylesheet(source, dest, config);
|
|
31
44
|
}
|
|
32
45
|
//# sourceMappingURL=cli.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/processor/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,KAAK,GACT,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/processor/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,C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AE,WAAW,CAAC,CAAC;QAC1B,OAAO;IACT,CAAC;IACD,IAAI,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;QAC1B,MAAM,CAAC,SAAS,CAAC,UAAU,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;IACtD,CAAC;IAED,qEAAqE;IACrE,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACpE,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACvE,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAExD,OAAO,MAAM,iBAAiB,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import fs from 'node:fs/promises';\nimport { parseArgs } from 'node:util';\nimport path from 'node:path';\nimport { processStylesheet } from './index.ts';\nimport { print, printError } from '../cli/print.ts';\nimport { type ArgotConfig } from '../config/types.ts';\nimport { ANSI_YELLOW } from '../cli/ansiColors.ts';\n\nconst USAGE =\n 'Usage: argot <input.css> <output.css> [--lint-config=\"path/to/config.js\"]\\n';\n\nexport async function runProcessor(args: string[], config: ArgotConfig = {}) {\n // TODO: helper for parseArgs. catches TypeError and prints help string\n const { positionals, values } = parseArgs({\n args,\n allowPositionals: true,\n options: {\n 'lint-config': { type: 'string', short: 'c' },\n help: { type: 'boolean', short: 'h', default: false },\n verbose: { type: 'boolean' },\n },\n });\n\n if (!config.processor) {\n config.processor = {};\n }\n\n if (positionals.length === 2) {\n config.processor.source = positionals[0];\n config.processor.destination = positionals[1];\n }\n\n if (!config.processor.source || !config.processor.destination) {\n printError(`Error: cssSource and cssDest must both be provided`);\n print(USAGE, ANSI_YELLOW);\n return;\n }\n if (values.help) {\n print(USAGE, ANSI_YELLOW);\n return;\n }\n if (values['lint-config']) {\n config.processor.lintConfig = values['lint-config'];\n }\n\n // TODO: resolve path relative to config file if not from positionals\n const source = path.resolve(process.cwd(), config.processor.source);\n const dest = path.resolve(process.cwd(), config.processor.destination);\n await fs.mkdir(path.dirname(dest), { recursive: true });\n\n return await processStylesheet(source, dest, config);\n}\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { ArgotConfig } from '../config/types.ts';
|
|
1
2
|
/**
|
|
2
3
|
* Processes stylesheet and outputs destination css
|
|
3
4
|
* @param sourceFile fully-qualified source filename
|
|
4
5
|
* @param destFile fully-qualified destination filename
|
|
5
6
|
*/
|
|
6
|
-
declare function processStylesheet(sourceFile: string, destFile: string,
|
|
7
|
+
declare function processStylesheet(sourceFile: string, destFile: string, config: ArgotConfig): Promise<void>;
|
|
7
8
|
export { processStylesheet };
|
package/dist/processor/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
|
-
import postcss from 'postcss';
|
|
2
|
+
import postcss, {} from 'postcss';
|
|
3
3
|
import reporter from 'postcss-reporter';
|
|
4
4
|
import cssnano from 'cssnano';
|
|
5
5
|
import stylelint from 'stylelint';
|
|
@@ -12,7 +12,7 @@ import defaultLintConfig from "./stylelintDefault.js";
|
|
|
12
12
|
* @param sourceFile fully-qualified source filename
|
|
13
13
|
* @param destFile fully-qualified destination filename
|
|
14
14
|
*/
|
|
15
|
-
async function processStylesheet(sourceFile, destFile,
|
|
15
|
+
async function processStylesheet(sourceFile, destFile, config) {
|
|
16
16
|
let css;
|
|
17
17
|
try {
|
|
18
18
|
css = await fs.readFile(sourceFile, 'utf8');
|
|
@@ -20,21 +20,44 @@ async function processStylesheet(sourceFile, destFile, lintConfigFile) {
|
|
|
20
20
|
catch (error) {
|
|
21
21
|
throw new Error(`Cannot read stylesheet "${sourceFile}": ${error.code}`, { cause: error });
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
const minify = config.processor?.minify ?? true;
|
|
24
|
+
if (minify === 'both') {
|
|
25
|
+
const unminified = await runPipeline(css, sourceFile, destFile, config, false);
|
|
26
|
+
await writeProcessedCss(destFile, unminified.css);
|
|
27
|
+
const minDest = minifiedDestination(destFile);
|
|
28
|
+
const minified = await postcss([cssnano()]).process(unminified.css, {
|
|
29
|
+
from: destFile,
|
|
30
|
+
to: minDest,
|
|
31
|
+
});
|
|
32
|
+
await writeProcessedCss(minDest, minified.css);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const result = await runPipeline(css, sourceFile, destFile, config, minify === true);
|
|
36
|
+
await writeProcessedCss(destFile, result.css);
|
|
37
|
+
}
|
|
38
|
+
async function runPipeline(css, from, to, config, minify) {
|
|
39
|
+
return postcss(buildPipelinePlugins(config.processor?.lintConfig, minify)).process(css, { from, to });
|
|
40
|
+
}
|
|
41
|
+
function buildPipelinePlugins(lintConfig, minify) {
|
|
42
|
+
const plugins = [atImport(), getStylelint(lintConfig)];
|
|
43
|
+
if (minify) {
|
|
44
|
+
plugins.push(cssnano());
|
|
45
|
+
}
|
|
46
|
+
plugins.push(reporter({ clearReportedMessages: true }));
|
|
47
|
+
return plugins;
|
|
48
|
+
}
|
|
49
|
+
function minifiedDestination(destFile) {
|
|
50
|
+
return /\.css$/i.test(destFile)
|
|
51
|
+
? destFile.replace(/\.css$/i, '.min.css')
|
|
52
|
+
: `${destFile}.min.css`;
|
|
53
|
+
}
|
|
54
|
+
async function writeProcessedCss(destFile, css) {
|
|
32
55
|
try {
|
|
33
|
-
await fs.writeFile(destFile,
|
|
34
|
-
print(`Wrote output CSS: ${destFile}`, ANSI_GREEN);
|
|
56
|
+
await fs.writeFile(destFile, css);
|
|
57
|
+
print(`Wrote output CSS: ${destFile}\n`, ANSI_GREEN);
|
|
35
58
|
}
|
|
36
59
|
catch (error) {
|
|
37
|
-
throw new Error(`Cannot write stylesheet ${destFile}: ${error.code}`, { cause: error });
|
|
60
|
+
throw new Error(`Cannot write stylesheet ${destFile}: ${error.code}\n`, { cause: error });
|
|
38
61
|
}
|
|
39
62
|
}
|
|
40
63
|
function getStylelint(userConfigFile) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/processor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,OAAO,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/processor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,OAAO,EAAE,EAAuB,MAAM,SAAS,CAAC;AACvD,OAAO,QAAQ,MAAM,kBAAkB,CAAC;AACxC,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,iBAAiB,MAAM,uBAAuB,CAAC;AAGtD;;;;GAIG;AACH,KAAK,UAAU,iBAAiB,CAC9B,UAAkB,EAClB,QAAgB,EAChB,MAAmB;IAEnB,IAAI,GAAG,CAAC;IACR,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,2BAA2B,UAAU,MAAO,KAA+B,CAAC,IAAI,EAAE,EAClF,EAAE,KAAK,EAAE,KAAK,EAA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CAAC;IACzE,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,qBAAqB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACxD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,mBAAmB,CAAC,QAAgB;IAC3C,OAAO,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC7B,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC;QACzC,CAAC,CAAC,GAAG,QAAQ,UAAU,CAAC;AAC5B,CAAC;AAED,KAAK,UAAU,iBAAiB,CAAC,QAAgB,EAAE,GAAW;IAC5D,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QAClC,KAAK,CAAC,qBAAqB,QAAQ,IAAI,EAAE,UAAU,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,2BAA2B,QAAQ,KAAM,KAA+B,CAAC,IAAI,IAAI,EACjF,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,cAAuB;IAC3C,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,SAAS,CAAC,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,SAAS,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC,CAAC;AAClD,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import fs from 'node:fs/promises';\nimport postcss, { type AcceptedPlugin } from 'postcss';\nimport reporter from 'postcss-reporter';\nimport cssnano from 'cssnano';\nimport stylelint from 'stylelint';\nimport atImport from './atImport.ts';\nimport { print } from '../cli/print.ts';\nimport { ANSI_GREEN } from '../cli/ansiColors.ts';\nimport defaultLintConfig from './stylelintDefault.ts';\nimport type { ArgotConfig } from '../config/types.ts';\n\n/**\n * Processes stylesheet and outputs destination css\n * @param sourceFile fully-qualified source filename\n * @param destFile fully-qualified destination filename\n */\nasync function processStylesheet(\n sourceFile: string,\n destFile: string,\n config: ArgotConfig,\n) {\n let css;\n try {\n css = await fs.readFile(sourceFile, 'utf8');\n } catch (error) {\n throw new Error(\n `Cannot read stylesheet \"${sourceFile}\": ${(error as NodeJS.ErrnoException).code}`,\n { cause: error },\n );\n }\n\n const minify = config.processor?.minify ?? true;\n\n if (minify === 'both') {\n const unminified = await runPipeline(\n css,\n sourceFile,\n destFile,\n config,\n false,\n );\n await writeProcessedCss(destFile, unminified.css);\n\n const minDest = minifiedDestination(destFile);\n const minified = await postcss([cssnano()]).process(unminified.css, {\n from: destFile,\n to: minDest,\n });\n await writeProcessedCss(minDest, minified.css);\n return;\n }\n\n const result = await runPipeline(\n css,\n sourceFile,\n destFile,\n config,\n minify === true,\n );\n await writeProcessedCss(destFile, result.css);\n}\n\nasync function runPipeline(\n css: string,\n from: string,\n to: string,\n config: ArgotConfig,\n minify: boolean,\n) {\n return postcss(\n buildPipelinePlugins(config.processor?.lintConfig, minify),\n ).process(css, { from, to });\n}\n\nfunction buildPipelinePlugins(\n lintConfig: string | undefined,\n minify: boolean,\n): AcceptedPlugin[] {\n const plugins: AcceptedPlugin[] = [atImport(), getStylelint(lintConfig)];\n if (minify) {\n plugins.push(cssnano());\n }\n plugins.push(reporter({ clearReportedMessages: true }));\n return plugins;\n}\n\nfunction minifiedDestination(destFile: string): string {\n return /\\.css$/i.test(destFile)\n ? destFile.replace(/\\.css$/i, '.min.css')\n : `${destFile}.min.css`;\n}\n\nasync function writeProcessedCss(destFile: string, css: string) {\n try {\n await fs.writeFile(destFile, css);\n print(`Wrote output CSS: ${destFile}\\n`, ANSI_GREEN);\n } catch (error) {\n throw new Error(\n `Cannot write stylesheet ${destFile}: ${(error as NodeJS.ErrnoException).code}\\n`,\n { cause: error },\n );\n }\n}\n\nfunction getStylelint(userConfigFile?: string) {\n if (userConfigFile) {\n return stylelint({ configFile: userConfigFile });\n }\n\n return stylelint({ config: defaultLintConfig });\n}\n\nexport { processStylesheet };\n"]}
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
// export const strict = {
|
|
2
|
-
// extends: ['stylelint-config-standard'],
|
|
3
|
-
// rules: {
|
|
4
|
-
// 'alpha-value-notation': 'number',
|
|
5
|
-
// 'at-rule-empty-line-before': [
|
|
6
|
-
// 'always',
|
|
7
|
-
// {
|
|
8
|
-
// except: ['blockless-after-same-name-blockless', 'first-nested'],
|
|
9
|
-
// ignore: ['after-comment', 'blockless-after-same-name-blockless'],
|
|
10
|
-
// },
|
|
11
|
-
// ],
|
|
12
|
-
// 'custom-property-pattern': ['^_?([a-z][a-z0-9]*)([-_]{1,2}[a-z0-9]+)*$'],
|
|
13
|
-
// },
|
|
14
|
-
// };
|
|
15
1
|
import recommended from 'stylelint-config-recommended';
|
|
2
|
+
import colorContrast from "../stylelint/rules/colorContrast.js";
|
|
16
3
|
export default {
|
|
17
4
|
extends: [recommended],
|
|
5
|
+
plugins: [colorContrast],
|
|
6
|
+
rules: {
|
|
7
|
+
'argot/color-contrast': true,
|
|
8
|
+
},
|
|
18
9
|
};
|
|
19
10
|
//# sourceMappingURL=stylelintDefault.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stylelintDefault.js","sourceRoot":"","sources":["../../src/processor/stylelintDefault.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"stylelintDefault.js","sourceRoot":"","sources":["../../src/processor/stylelintDefault.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,8BAA8B,CAAC;AACvD,OAAO,aAAa,MAAM,qCAAqC,CAAC;AAEhE,eAAe;IACb,OAAO,EAAE,CAAC,WAAW,CAAC;IACtB,OAAO,EAAE,CAAC,aAAa,CAAC;IACxB,KAAK,EAAE;QACL,sBAAsB,EAAE,IAAI;KAC7B;CACF,CAAC","sourcesContent":["import recommended from 'stylelint-config-recommended';\nimport colorContrast from '../stylelint/rules/colorContrast.ts';\n\nexport default {\n extends: [recommended],\n plugins: [colorContrast],\n rules: {\n 'argot/color-contrast': true,\n },\n};\n"]}
|