argot-css 0.0.0-stage → 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 +20 -0
- package/README.md +38 -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/getConfig.d.ts +11 -0
- package/dist/cli/getConfig.js +37 -0
- package/dist/cli/getConfig.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 +47 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/usage.d.ts +2 -0
- package/dist/cli/usage.js +20 -0
- package/dist/cli/usage.js.map +1 -0
- 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 +3 -0
- package/dist/palette/cli.js +44 -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 +8 -0
- package/dist/palette/generatePalette.js +96 -0
- package/dist/palette/generatePalette.js.map +1 -0
- package/dist/palette/index.d.ts +6 -0
- package/dist/palette/index.js +6 -0
- package/dist/palette/index.js.map +1 -0
- package/dist/palette/node.d.ts +20 -0
- package/dist/palette/node.js +43 -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 +9 -0
- package/dist/palette/render.js +52 -0
- package/dist/palette/render.js.map +1 -0
- package/dist/palette/types.d.ts +57 -0
- package/dist/palette/types.js +27 -0
- package/dist/palette/types.js.map +1 -0
- package/dist/palette/validation.d.ts +12 -0
- package/dist/palette/validation.js +122 -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 +2 -0
- package/dist/processor/cli.js +45 -0
- package/dist/processor/cli.js.map +1 -0
- package/dist/processor/index.d.ts +8 -0
- package/dist/processor/index.js +70 -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 +8 -0
- package/dist/processor/stylelintDefault.js +10 -0
- package/dist/processor/stylelintDefault.js.map +1 -0
- 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 +3 -0
- package/dist/semantics/cli.js +41 -0
- package/dist/semantics/cli.js.map +1 -0
- package/dist/semantics/generate.d.ts +23 -0
- package/dist/semantics/generate.js +50 -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 +17 -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/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.d.ts +3 -0
- package/dist/stylelint/rules/valid-token.js +32 -0
- package/dist/stylelint/rules/valid-token.js.map +1 -0
- package/package.json +114 -4
- package/templates/base.css +53 -0
- package/templates/modules/index.css +0 -0
- package/templates/semantics-core.css +94 -0
- package/templates/semantics-extended.css +115 -0
- package/templates/styles.css +8 -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,44 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util';
|
|
2
|
+
import { writePalette } from "./node.js";
|
|
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 palette [output.css] [--force] [--dry-run]\n';
|
|
7
|
+
function runPalette(args, config = {}) {
|
|
8
|
+
const { values, positionals } = parseArgs({
|
|
9
|
+
args,
|
|
10
|
+
allowPositionals: true,
|
|
11
|
+
options: {
|
|
12
|
+
force: { type: 'boolean', default: false },
|
|
13
|
+
'dry-run': { type: 'boolean', default: false },
|
|
14
|
+
help: { type: 'boolean', short: 'h', default: false },
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
if (values.help) {
|
|
18
|
+
print(USAGE, ANSI_YELLOW);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (positionals.length > 1) {
|
|
22
|
+
printError('Error: too many arguments');
|
|
23
|
+
print(USAGE, ANSI_YELLOW);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
const palette = {
|
|
27
|
+
seedColors: [],
|
|
28
|
+
...config.palette,
|
|
29
|
+
...(positionals[0] !== undefined ? { output: positionals[0] } : {}),
|
|
30
|
+
};
|
|
31
|
+
const split = splitPaletteConfig(palette);
|
|
32
|
+
const output = split.output ?? `${getScaffoldDirectory(config)}/vars-primitive.css`;
|
|
33
|
+
const result = writePalette(output, split.definition, {
|
|
34
|
+
force: values.force,
|
|
35
|
+
dryRun: values['dry-run'],
|
|
36
|
+
});
|
|
37
|
+
console.log(`${result.written ? 'Wrote' : 'Would write'} ${result.path}`);
|
|
38
|
+
}
|
|
39
|
+
function splitPaletteConfig(palette) {
|
|
40
|
+
const { output, ...definition } = palette;
|
|
41
|
+
return { output, definition };
|
|
42
|
+
}
|
|
43
|
+
export { runPalette };
|
|
44
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/palette/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACpD,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AAG,oBAAoB,CAAC,MAAM,CAAC,qBAAqB,CAAC;IACvE,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE;QACpD,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC;KAC1B,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;AAC5E,CAAC;AAED,SAAS,kBAAkB,CAAC,OAAsB;IAIhD,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,GAAG,OAAO,CAAC;IAC1C,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AAChC,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import { parseArgs } from 'node:util';\nimport { writePalette } from './node.ts';\nimport { print, printError } from '../cli/print.ts';\nimport { ANSI_YELLOW } from '../cli/ansiColors.ts';\nimport { getScaffoldDirectory } from '../config/util.ts';\nimport type {\n ArgotConfig,\n PaletteConfig,\n PaletteDefinition,\n} from '../config/types.ts';\n\nconst USAGE = 'Usage: argot palette [output.css] [--force] [--dry-run]\\n';\n\nfunction runPalette(args: string[], config: ArgotConfig = {}): void {\n const { values, positionals } = parseArgs({\n args,\n allowPositionals: true,\n options: {\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 if (values.help) {\n print(USAGE, ANSI_YELLOW);\n return;\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 palette: PaletteConfig = {\n seedColors: [],\n ...config.palette,\n ...(positionals[0] !== undefined ? { output: positionals[0] } : {}),\n };\n const split = splitPaletteConfig(palette);\n const output =\n split.output ?? `${getScaffoldDirectory(config)}/vars-primitive.css`;\n const result = writePalette(output, split.definition, {\n force: values.force,\n dryRun: values['dry-run'],\n });\n console.log(`${result.written ? 'Wrote' : 'Would write'} ${result.path}`);\n}\n\nfunction splitPaletteConfig(palette: PaletteConfig): {\n output?: string;\n definition: PaletteDefinition;\n} {\n const { output, ...definition } = palette;\n return { output, definition };\n}\n\nexport { runPalette };\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const NAMES = {
|
|
2
|
+
0: 'raspberry',
|
|
3
|
+
15: 'cherry',
|
|
4
|
+
30: 'red',
|
|
5
|
+
45: 'sienna',
|
|
6
|
+
60: 'orange',
|
|
7
|
+
75: 'gold',
|
|
8
|
+
90: 'lemon',
|
|
9
|
+
105: 'yellow',
|
|
10
|
+
120: 'avocado',
|
|
11
|
+
135: 'jungle',
|
|
12
|
+
150: 'green',
|
|
13
|
+
165: 'mint',
|
|
14
|
+
180: 'seafoam',
|
|
15
|
+
195: 'teal',
|
|
16
|
+
210: 'cyan',
|
|
17
|
+
225: 'sapphire',
|
|
18
|
+
240: 'azure',
|
|
19
|
+
255: 'blue',
|
|
20
|
+
270: 'indigo',
|
|
21
|
+
285: 'violet',
|
|
22
|
+
300: 'lilac',
|
|
23
|
+
315: 'purple',
|
|
24
|
+
330: 'grape',
|
|
25
|
+
345: 'pink',
|
|
26
|
+
360: 'raspberry',
|
|
27
|
+
};
|
|
28
|
+
const NEUTRAL_NAMES = {
|
|
29
|
+
0: 'dust',
|
|
30
|
+
60: 'sand',
|
|
31
|
+
120: 'stone',
|
|
32
|
+
180: 'sage',
|
|
33
|
+
240: 'slate',
|
|
34
|
+
300: 'ash',
|
|
35
|
+
360: 'dust',
|
|
36
|
+
};
|
|
37
|
+
export function generateName(color) {
|
|
38
|
+
const { c, h } = color;
|
|
39
|
+
let rounded, names;
|
|
40
|
+
if (c >= 0.05) {
|
|
41
|
+
names = NAMES;
|
|
42
|
+
rounded = Math.round(h / 15) * 15;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
names = NEUTRAL_NAMES;
|
|
46
|
+
rounded = Math.round(h / 60) * 60;
|
|
47
|
+
}
|
|
48
|
+
return names[rounded] || 'unnamed';
|
|
49
|
+
}
|
|
50
|
+
export function dedupeNames(colors) {
|
|
51
|
+
const names = [];
|
|
52
|
+
const all = [...colors];
|
|
53
|
+
all.forEach((color) => {
|
|
54
|
+
if (!color.name) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
names.push(color.name);
|
|
58
|
+
const count = names.filter((n) => n === color.name).length;
|
|
59
|
+
if (count > 1) {
|
|
60
|
+
color.name = `${color.name}${count}`;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return colors;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=generateName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateName.js","sourceRoot":"","sources":["../../src/palette/generateName.ts"],"names":[],"mappings":"AAEA,MAAM,KAAK,GAAG;IACZ,CAAC,EAAE,WAAW;IACd,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,MAAM;IACV,EAAE,EAAE,OAAO;IACX,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,UAAU;IACf,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,WAAW;CACjB,CAAC;AAC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C,IAAI,GAAG,KAAK,EAAE,CAAC;QACvC,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { OklchColor, NormalizedSeedColor } from './types.ts';\n\nconst NAMES = {\n 0: 'raspberry',\n 15: 'cherry',\n 30: 'red',\n 45: 'sienna',\n 60: 'orange',\n 75: 'gold',\n 90: 'lemon',\n 105: 'yellow',\n 120: 'avocado',\n 135: 'jungle',\n 150: 'green',\n 165: 'mint',\n 180: 'seafoam',\n 195: 'teal',\n 210: 'cyan',\n 225: 'sapphire',\n 240: 'azure',\n 255: 'blue',\n 270: 'indigo',\n 285: 'violet',\n 300: 'lilac',\n 315: 'purple',\n 330: 'grape',\n 345: 'pink',\n 360: 'raspberry',\n};\nconst NEUTRAL_NAMES = {\n 0: 'dust',\n 60: 'sand',\n 120: 'stone',\n 180: 'sage',\n 240: 'slate',\n 300: 'ash',\n 360: 'dust',\n};\n\nexport function generateName(color: OklchColor): string {\n const { c, h } = color;\n let rounded: number, names: { [k: number]: string };\n if (c >= 0.05) {\n names = NAMES;\n rounded = Math.round(h / 15) * 15;\n } else {\n names = NEUTRAL_NAMES;\n rounded = Math.round(h / 60) * 60;\n }\n\n return names[rounded] || 'unnamed';\n}\n\nexport function dedupeNames(colors: NormalizedSeedColor[]) {\n const names: string[] = [];\n const all = [...colors];\n all.forEach((color) => {\n if (!color.name) {\n return;\n }\n\n names.push(color.name);\n const count = names.filter((n) => n === color.name).length;\n\n if (count > 1) {\n color.name = `${color.name}${count}`;\n }\n });\n return colors;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PaletteDefinition } from '../config/types.ts';
|
|
2
|
+
import type { Palette } from './types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Generate serializable raw OKLCH scales, before gamut mapping or rounding.
|
|
5
|
+
* Steps and baseStep are one-based; input order is preserved without mutation.
|
|
6
|
+
*/
|
|
7
|
+
declare function generatePalette(definition: PaletteDefinition): Palette;
|
|
8
|
+
export { generatePalette };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { normalizePaletteDefinition } from "./validation.js";
|
|
2
|
+
const LIGHTNESS = Object.freeze([
|
|
3
|
+
0.98, 0.97, 0.93, 0.84, 0.8, 0.71, 0.66, 0.58, 0.53, 0.49, 0.42, 0.35, 0.27,
|
|
4
|
+
0.2, 0.16, 0.1,
|
|
5
|
+
]);
|
|
6
|
+
const CHROMA = Object.freeze([
|
|
7
|
+
0.14, 0.29, 0.48, 0.57, 0.76, 0.9, 0.95, 1, 0.95, 0.9, 0.81, 0.71, 0.57, 0.43,
|
|
8
|
+
0.33, 0.24,
|
|
9
|
+
]);
|
|
10
|
+
/**
|
|
11
|
+
* Generate serializable raw OKLCH scales, before gamut mapping or rounding.
|
|
12
|
+
* Steps and baseStep are one-based; input order is preserved without mutation.
|
|
13
|
+
*/
|
|
14
|
+
function generatePalette(definition) {
|
|
15
|
+
const normalized = normalizePaletteDefinition(definition);
|
|
16
|
+
const colors = normalized.seedColors.map((seed) => generateScale(seed, normalized.options));
|
|
17
|
+
return { version: 1, options: normalized.options, colors };
|
|
18
|
+
}
|
|
19
|
+
function generateScale(seed, options) {
|
|
20
|
+
const { lightnessCurve = 'uniform', chromaCurve = 'centered' } = options;
|
|
21
|
+
const index = findTargetIndex(seed.l);
|
|
22
|
+
const chromaScale = chromaCurve === 'weighted' ? buildChromaCurve(index, seed.c) : CHROMA;
|
|
23
|
+
const anchor = lightnessCurve === 'centered' ? 8 : index;
|
|
24
|
+
// Centered lightness rescales the original chroma curve at step 9; it does
|
|
25
|
+
// not rebuild the weighted curve around that step.
|
|
26
|
+
let chromaMultiplier = 1;
|
|
27
|
+
if (lightnessCurve === 'centered') {
|
|
28
|
+
chromaMultiplier = seed.c / chromaScale[8];
|
|
29
|
+
}
|
|
30
|
+
else if (chromaCurve === 'centered') {
|
|
31
|
+
chromaMultiplier = seed.c / chromaScale[index];
|
|
32
|
+
}
|
|
33
|
+
if (!Number.isFinite(chromaMultiplier)) {
|
|
34
|
+
// handle divide by zero for 0-chroma values
|
|
35
|
+
chromaMultiplier = 0;
|
|
36
|
+
}
|
|
37
|
+
const lightness = lightnessCurve === 'uniform'
|
|
38
|
+
? LIGHTNESS
|
|
39
|
+
: buildInclusiveLightnessCurve(seed.l, anchor);
|
|
40
|
+
return {
|
|
41
|
+
name: seed.name,
|
|
42
|
+
baseStep: anchor + 1,
|
|
43
|
+
steps: lightness.map((l, index) => ({
|
|
44
|
+
step: index + 1,
|
|
45
|
+
l,
|
|
46
|
+
c: chromaScale[index] * chromaMultiplier,
|
|
47
|
+
h: seed.h,
|
|
48
|
+
})),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function findTargetIndex(lightness) {
|
|
52
|
+
const after = LIGHTNESS.findIndex((value) => value < lightness);
|
|
53
|
+
const before = after !== -1 ? after - 1 : 15;
|
|
54
|
+
if (after === -1)
|
|
55
|
+
return before;
|
|
56
|
+
if (before === -1)
|
|
57
|
+
return after;
|
|
58
|
+
const beforeDiff = LIGHTNESS[before] - lightness;
|
|
59
|
+
const afterDiff = lightness - LIGHTNESS[after];
|
|
60
|
+
return beforeDiff < afterDiff ? before : after;
|
|
61
|
+
}
|
|
62
|
+
function buildChromaCurve(index, peakValue) {
|
|
63
|
+
const endValue = peakValue < 0.04 ? 0 : 0.01;
|
|
64
|
+
const beforeSteps = index;
|
|
65
|
+
const afterSteps = 15 - index;
|
|
66
|
+
const beforeInterval = (peakValue - endValue) / beforeSteps;
|
|
67
|
+
const afterInterval = (peakValue - endValue) / afterSteps;
|
|
68
|
+
const scale = [];
|
|
69
|
+
for (let i = beforeSteps; i > 0; i--) {
|
|
70
|
+
scale.push(peakValue - i * beforeInterval);
|
|
71
|
+
}
|
|
72
|
+
scale.push(peakValue);
|
|
73
|
+
for (let i = 1; i <= afterSteps; i++) {
|
|
74
|
+
scale.push(peakValue - i * afterInterval);
|
|
75
|
+
}
|
|
76
|
+
return scale;
|
|
77
|
+
}
|
|
78
|
+
function buildInclusiveLightnessCurve(lightness, index) {
|
|
79
|
+
const maxLightness = LIGHTNESS[0];
|
|
80
|
+
const minLightness = LIGHTNESS[15];
|
|
81
|
+
const lSteps = index;
|
|
82
|
+
const dSteps = 15 - index;
|
|
83
|
+
const lInterval = (maxLightness - lightness) / lSteps;
|
|
84
|
+
const dInterval = (lightness - minLightness) / dSteps;
|
|
85
|
+
const lightnessScale = [];
|
|
86
|
+
for (let i = 0; i < lSteps; i++) {
|
|
87
|
+
lightnessScale.push(maxLightness - i * lInterval);
|
|
88
|
+
}
|
|
89
|
+
lightnessScale.push(lightness);
|
|
90
|
+
for (let i = 1; i <= dSteps; i++) {
|
|
91
|
+
lightnessScale.push(lightness - i * dInterval);
|
|
92
|
+
}
|
|
93
|
+
return lightnessScale;
|
|
94
|
+
}
|
|
95
|
+
export { generatePalette };
|
|
96
|
+
//# sourceMappingURL=generatePalette.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generatePalette.js","sourceRoot":"","sources":["../../src/palette/generatePalette.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAI7D,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IAC3E,GAAG,EAAE,IAAI,EAAE,GAAG;CACf,CAAC,CAAC;AACH,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3B,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IAC7E,IAA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MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,cAAc,CAAC,IAAI,CAAC,YAAY,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC;IACpD,CAAC;IACD,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACjC,cAAc,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,OAAO,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import { normalizePaletteDefinition } from './validation.ts';\nimport type { PaletteDefinition } from '../config/types.ts';\nimport type { Palette, PaletteOptions, NormalizedSeedColor } from './types.ts';\n\nconst LIGHTNESS = Object.freeze([\n 0.98, 0.97, 0.93, 0.84, 0.8, 0.71, 0.66, 0.58, 0.53, 0.49, 0.42, 0.35, 0.27,\n 0.2, 0.16, 0.1,\n]);\nconst CHROMA = Object.freeze([\n 0.14, 0.29, 0.48, 0.57, 0.76, 0.9, 0.95, 1, 0.95, 0.9, 0.81, 0.71, 0.57, 0.43,\n 0.33, 0.24,\n]);\n\n/**\n * Generate serializable raw OKLCH scales, before gamut mapping or rounding.\n * Steps and baseStep are one-based; input order is preserved without mutation.\n */\nfunction generatePalette(definition: PaletteDefinition): Palette {\n const normalized = normalizePaletteDefinition(definition);\n\n const colors = normalized.seedColors.map((seed) =>\n generateScale(seed, normalized.options),\n );\n return { version: 1, options: normalized.options, colors };\n}\n\nfunction generateScale(seed: NormalizedSeedColor, options: PaletteOptions) {\n const { lightnessCurve = 'uniform', chromaCurve = 'centered' } = options;\n const index = findTargetIndex(seed.l);\n const chromaScale =\n chromaCurve === 'weighted' ? buildChromaCurve(index, seed.c) : CHROMA;\n const anchor = lightnessCurve === 'centered' ? 8 : index;\n // Centered lightness rescales the original chroma curve at step 9; it does\n // not rebuild the weighted curve around that step.\n let chromaMultiplier = 1;\n if (lightnessCurve === 'centered') {\n chromaMultiplier = seed.c / chromaScale[8];\n } else if (chromaCurve === 'centered') {\n chromaMultiplier = seed.c / chromaScale[index];\n }\n if (!Number.isFinite(chromaMultiplier)) {\n // handle divide by zero for 0-chroma values\n chromaMultiplier = 0;\n }\n const lightness =\n lightnessCurve === 'uniform'\n ? LIGHTNESS\n : buildInclusiveLightnessCurve(seed.l, anchor);\n return {\n name: seed.name,\n baseStep: anchor + 1,\n steps: lightness.map((l, index) => ({\n step: index + 1,\n l,\n c: chromaScale[index] * chromaMultiplier,\n h: seed.h,\n })),\n };\n}\n\nfunction findTargetIndex(lightness: number): number {\n const after = LIGHTNESS.findIndex((value) => value < lightness);\n const before = after !== -1 ? after - 1 : 15;\n if (after === -1) return before;\n if (before === -1) return after;\n const beforeDiff = LIGHTNESS[before] - lightness;\n const afterDiff = lightness - LIGHTNESS[after];\n return beforeDiff < afterDiff ? before : after;\n}\n\nfunction buildChromaCurve(index: number, peakValue: number): number[] {\n const endValue = peakValue < 0.04 ? 0 : 0.01;\n const beforeSteps = index;\n const afterSteps = 15 - index;\n const beforeInterval = (peakValue - endValue) / beforeSteps;\n const afterInterval = (peakValue - endValue) / afterSteps;\n const scale = [];\n for (let i = beforeSteps; i > 0; i--) {\n scale.push(peakValue - i * beforeInterval);\n }\n scale.push(peakValue);\n for (let i = 1; i <= afterSteps; i++) {\n scale.push(peakValue - i * afterInterval);\n }\n return scale;\n}\n\nfunction buildInclusiveLightnessCurve(\n lightness: number,\n index: number,\n): number[] {\n const maxLightness = LIGHTNESS[0];\n const minLightness = LIGHTNESS[15];\n\n const lSteps = index;\n const dSteps = 15 - index;\n const lInterval = (maxLightness - lightness) / lSteps;\n const dInterval = (lightness - minLightness) / dSteps;\n\n const lightnessScale = [];\n for (let i = 0; i < lSteps; i++) {\n lightnessScale.push(maxLightness - i * lInterval);\n }\n lightnessScale.push(lightness);\n for (let i = 1; i <= dSteps; i++) {\n lightnessScale.push(lightness - i * dInterval);\n }\n return lightnessScale;\n}\n\nexport { generatePalette };\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { normalizePaletteDefinition } from './validation.ts';
|
|
2
|
+
export { generatePalette } from './generatePalette.ts';
|
|
3
|
+
export { renderPaletteCss, generatePaletteCss } from './render.ts';
|
|
4
|
+
export { parseCssColor } from './parseCssColor.ts';
|
|
5
|
+
export type { ChromaCurve, ColorFormat, LightnessCurve, NormalizedPaletteDefinition, OklchColor, Palette, PaletteScale, PaletteOptions, PaletteStep, } from './types.ts';
|
|
6
|
+
export type { PaletteDefinition, SeedColor } from '../config/types.ts';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Browser-safe public entrypoint. Keep Node file adapters in ./node.ts.
|
|
2
|
+
export { normalizePaletteDefinition } from "./validation.js";
|
|
3
|
+
export { generatePalette } from "./generatePalette.js";
|
|
4
|
+
export { renderPaletteCss, generatePaletteCss } from "./render.js";
|
|
5
|
+
export { parseCssColor } from "./parseCssColor.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/palette/index.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["// Browser-safe public entrypoint. Keep Node file adapters in ./node.ts.\nexport { normalizePaletteDefinition } from './validation.ts';\nexport { generatePalette } from './generatePalette.ts';\nexport { renderPaletteCss, generatePaletteCss } from './render.ts';\nexport { parseCssColor } from './parseCssColor.ts';\nexport type {\n ChromaCurve,\n ColorFormat,\n LightnessCurve,\n NormalizedPaletteDefinition,\n OklchColor,\n Palette,\n PaletteScale,\n PaletteOptions,\n PaletteStep,\n} from './types.ts';\nexport type { PaletteDefinition, SeedColor } from '../config/types.ts';\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { WriteOutputOptions } from '../lib/writeOutput.ts';
|
|
2
|
+
import type { PaletteDefinition } from '../config/types.ts';
|
|
3
|
+
import type { NormalizedPaletteDefinition } from './types.ts';
|
|
4
|
+
export type WritePaletteOptions = WriteOutputOptions;
|
|
5
|
+
export interface WritePaletteResult {
|
|
6
|
+
path: string;
|
|
7
|
+
css: string;
|
|
8
|
+
written: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** Load and validate a portable JSON definition, resolving paths only in Node. */
|
|
11
|
+
declare function loadPaletteDefinition(filename: string): NormalizedPaletteDefinition;
|
|
12
|
+
/**
|
|
13
|
+
* Write only explicitly designated output. Dry runs validate without writing.
|
|
14
|
+
* Exclusive creation protects existing files; forced writes reject symlinks
|
|
15
|
+
* and non-regular files rather than following them.
|
|
16
|
+
*
|
|
17
|
+
* outPath is used rather than optional definition.output
|
|
18
|
+
*/
|
|
19
|
+
declare function writePalette(outPath: string, definition: PaletteDefinition, options?: WritePaletteOptions): WritePaletteResult;
|
|
20
|
+
export { loadPaletteDefinition, writePalette };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { writeOutput } from "../lib/writeOutput.js";
|
|
4
|
+
import { normalizePaletteDefinition } from "./validation.js";
|
|
5
|
+
import { generatePaletteCss } from "./render.js";
|
|
6
|
+
/** Load and validate a portable JSON definition, resolving paths only in Node. */
|
|
7
|
+
function loadPaletteDefinition(filename) {
|
|
8
|
+
const resolved = path.resolve(filename);
|
|
9
|
+
let source;
|
|
10
|
+
try {
|
|
11
|
+
source = fs.readFileSync(resolved, 'utf8');
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
throw new Error(`Cannot read palette definition "${resolved}": ${error.code}`, { cause: error });
|
|
15
|
+
}
|
|
16
|
+
let definition;
|
|
17
|
+
try {
|
|
18
|
+
definition = JSON.parse(source);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
throw new Error(`Invalid JSON in palette definition "${resolved}"`);
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
return normalizePaletteDefinition(definition);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
throw new Error(`Invalid palette definition "${resolved}": ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Write only explicitly designated output. Dry runs validate without writing.
|
|
32
|
+
* Exclusive creation protects existing files; forced writes reject symlinks
|
|
33
|
+
* and non-regular files rather than following them.
|
|
34
|
+
*
|
|
35
|
+
* outPath is used rather than optional definition.output
|
|
36
|
+
*/
|
|
37
|
+
function writePalette(outPath, definition, options = {}) {
|
|
38
|
+
const css = generatePaletteCss(definition);
|
|
39
|
+
const { path: resolved, written } = writeOutput(outPath, css, options);
|
|
40
|
+
return { path: resolved, css, written };
|
|
41
|
+
}
|
|
42
|
+
export { loadPaletteDefinition, writePalette };
|
|
43
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/palette/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAYjD,kFAAkF;AAClF,SAAS,qBAAqB,CAAC,QAAgB;IAC7C,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,QA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Content":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { writeOutput } from '../lib/writeOutput.ts';\nimport type { WriteOutputOptions } from '../lib/writeOutput.ts';\nimport { normalizePaletteDefinition } from './validation.ts';\nimport { generatePaletteCss } from './render.ts';\nimport type { PaletteDefinition } from '../config/types.ts';\nimport type { NormalizedPaletteDefinition } from './types.ts';\n\nexport type WritePaletteOptions = WriteOutputOptions;\n\nexport interface WritePaletteResult {\n path: string;\n css: string;\n written: boolean;\n}\n\n/** Load and validate a portable JSON definition, resolving paths only in Node. */\nfunction loadPaletteDefinition(filename: string): NormalizedPaletteDefinition {\n const resolved = path.resolve(filename);\n let source;\n try {\n source = fs.readFileSync(resolved, 'utf8');\n } catch (error) {\n throw new Error(\n `Cannot read palette definition \"${resolved}\": ${(error as NodeJS.ErrnoException).code}`,\n { cause: error },\n );\n }\n let definition: unknown;\n try {\n definition = JSON.parse(source);\n } catch {\n throw new Error(`Invalid JSON in palette definition \"${resolved}\"`);\n }\n try {\n return normalizePaletteDefinition(definition);\n } catch (error) {\n throw new Error(\n `Invalid palette definition \"${resolved}\": ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n}\n\n/**\n * Write only explicitly designated output. Dry runs validate without writing.\n * Exclusive creation protects existing files; forced writes reject symlinks\n * and non-regular files rather than following them.\n *\n * outPath is used rather than optional definition.output\n */\nfunction writePalette(\n outPath: string,\n definition: PaletteDefinition,\n options: WritePaletteOptions = {},\n): WritePaletteResult {\n const css = generatePaletteCss(definition);\n const { path: resolved, written } = writeOutput(outPath, css, options);\n return { path: resolved, css, written };\n}\n\nexport { loadPaletteDefinition, writePalette };\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { OklchColor } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Optional input adapter for standalone opaque CSS colors. Palette definitions
|
|
4
|
+
* store the returned numeric coordinates, never the CSS string.
|
|
5
|
+
*/
|
|
6
|
+
declare function parseCssColor(value: string): OklchColor;
|
|
7
|
+
export { parseCssColor };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Color from 'colorjs.io';
|
|
2
|
+
import { checkCoordinates } from "./validation.js";
|
|
3
|
+
/**
|
|
4
|
+
* Optional input adapter for standalone opaque CSS colors. Palette definitions
|
|
5
|
+
* store the returned numeric coordinates, never the CSS string.
|
|
6
|
+
*/
|
|
7
|
+
function parseCssColor(value) {
|
|
8
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
9
|
+
throw new Error('color: expected an opaque CSS color string');
|
|
10
|
+
}
|
|
11
|
+
let color;
|
|
12
|
+
try {
|
|
13
|
+
color = new Color(value.trim()).to('oklch');
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
throw new Error('color: invalid or context-dependent CSS color');
|
|
17
|
+
}
|
|
18
|
+
if (color.alpha !== 1) {
|
|
19
|
+
throw new Error('color: expected an opaque color (alpha must be 1)');
|
|
20
|
+
}
|
|
21
|
+
const [l, c, h] = color.coords;
|
|
22
|
+
// Conversions of white can be a fraction above 1 due to floating-point error.
|
|
23
|
+
// This tolerance belongs to CSS conversion, not numeric definition validation.
|
|
24
|
+
if (typeof l !== 'number' ||
|
|
25
|
+
!Number.isFinite(l) ||
|
|
26
|
+
l < -1e-12 ||
|
|
27
|
+
l > 1 + 1e-12) {
|
|
28
|
+
throw new Error('color.l: expected finite lightness between 0 and 1');
|
|
29
|
+
}
|
|
30
|
+
const newL = Math.min(1, Math.max(0, l));
|
|
31
|
+
let newH = h;
|
|
32
|
+
// Achromatic CSS colors may have no hue; supply a numeric angle for handoff.
|
|
33
|
+
if (c === 0 && (h === null || Number.isNaN(h))) {
|
|
34
|
+
newH = 0;
|
|
35
|
+
}
|
|
36
|
+
const coordinates = { l: newL, c, h: newH };
|
|
37
|
+
checkCoordinates(coordinates, 'color');
|
|
38
|
+
return coordinates;
|
|
39
|
+
}
|
|
40
|
+
export { parseCssColor };
|
|
41
|
+
//# sourceMappingURL=parseCssColor.js.map
|
|
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AAC;IACb,6EAA6E;IAC7E,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/C,IAAI,GAAG,CAAC,CAAC;IACX,CAAC;IACD,MAAM,WAAW,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC;IAC5C,gBAAgB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACvC,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import Color from 'colorjs.io';\nimport { checkCoordinates } from './validation.ts';\nimport type { OklchColor } from './types.ts';\n\n/**\n * Optional input adapter for standalone opaque CSS colors. Palette definitions\n * store the returned numeric coordinates, never the CSS string.\n */\nfunction parseCssColor(value: string): OklchColor {\n if (typeof value !== 'string' || value.trim() === '') {\n throw new Error('color: expected an opaque CSS color string');\n }\n let color;\n try {\n color = new Color(value.trim()).to('oklch');\n } catch {\n throw new Error('color: invalid or context-dependent CSS color');\n }\n if (color.alpha !== 1) {\n throw new Error('color: expected an opaque color (alpha must be 1)');\n }\n const [l, c, h] = color.coords;\n\n // Conversions of white can be a fraction above 1 due to floating-point error.\n // This tolerance belongs to CSS conversion, not numeric definition validation.\n if (\n typeof l !== 'number' ||\n !Number.isFinite(l) ||\n l < -1e-12 ||\n l > 1 + 1e-12\n ) {\n throw new Error('color.l: expected finite lightness between 0 and 1');\n }\n const newL = Math.min(1, Math.max(0, l));\n\n let newH = h;\n // Achromatic CSS colors may have no hue; supply a numeric angle for handoff.\n if (c === 0 && (h === null || Number.isNaN(h))) {\n newH = 0;\n }\n const coordinates = { l: newL, c, h: newH };\n checkCoordinates(coordinates, 'color');\n return coordinates;\n}\n\nexport { parseCssColor };\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PaletteDefinition } from '../config/types.ts';
|
|
2
|
+
import type { Palette } from './types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Render a model returned by generatePalette without mutating its raw steps.
|
|
5
|
+
* Gamut mapping happens here, independently of CSS output format.
|
|
6
|
+
*/
|
|
7
|
+
declare function renderPaletteCss(palette: Palette): string;
|
|
8
|
+
declare function generatePaletteCss(definition: PaletteDefinition): string;
|
|
9
|
+
export { renderPaletteCss, generatePaletteCss };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Color from 'colorjs.io';
|
|
2
|
+
import { checkName } from "./validation.js";
|
|
3
|
+
import { generatePalette } from "./generatePalette.js";
|
|
4
|
+
/**
|
|
5
|
+
* Render a model returned by generatePalette without mutating its raw steps.
|
|
6
|
+
* Gamut mapping happens here, independently of CSS output format.
|
|
7
|
+
*/
|
|
8
|
+
function renderPaletteCss(palette) {
|
|
9
|
+
// const options = normalizeOptions(palette.options);
|
|
10
|
+
const blocks = palette.colors.map(({ name, baseStep, steps }) => {
|
|
11
|
+
checkName(name, 'palette color name');
|
|
12
|
+
const lines = steps.map(({ step, l, c, h }) => {
|
|
13
|
+
if (!Number.isInteger(step) || step < 1 || step > 16) {
|
|
14
|
+
throw new Error('palette step: expected an integer from 1 to 16');
|
|
15
|
+
}
|
|
16
|
+
return ` --${name}-${step}: ${formatColor({ l, c, h }, palette.options)};`;
|
|
17
|
+
});
|
|
18
|
+
if (!Number.isInteger(baseStep) || baseStep < 1 || baseStep > 16) {
|
|
19
|
+
throw new Error('palette baseStep: expected an integer from 1 to 16');
|
|
20
|
+
}
|
|
21
|
+
lines.push(` --${name}: var(--${name}-${baseStep});`);
|
|
22
|
+
return lines.join('\n');
|
|
23
|
+
});
|
|
24
|
+
return [
|
|
25
|
+
'/* Generated by Argot. */',
|
|
26
|
+
':root {',
|
|
27
|
+
blocks.join('\n\n'),
|
|
28
|
+
'}',
|
|
29
|
+
'',
|
|
30
|
+
].join('\n');
|
|
31
|
+
}
|
|
32
|
+
function formatColor({ l, c, h }, { format }) {
|
|
33
|
+
if (![l, c, h].every(Number.isFinite)) {
|
|
34
|
+
throw new Error('palette coordinates: expected finite OKLCH values');
|
|
35
|
+
}
|
|
36
|
+
const gamut = ['oklch', 'oklab', 'lch', 'lab'].includes(format)
|
|
37
|
+
? 'p3'
|
|
38
|
+
: 'srgb';
|
|
39
|
+
const color = new Color('oklch', [l, c, h]).toGamut({
|
|
40
|
+
space: gamut,
|
|
41
|
+
method: 'css',
|
|
42
|
+
});
|
|
43
|
+
if (format === 'hex') {
|
|
44
|
+
return color.to('srgb').toString({ format: 'hex', collapse: false });
|
|
45
|
+
}
|
|
46
|
+
return color.to(format).toString({ precision: 6 });
|
|
47
|
+
}
|
|
48
|
+
function generatePaletteCss(definition) {
|
|
49
|
+
return renderPaletteCss(generatePalette(definition));
|
|
50
|
+
}
|
|
51
|
+
export { renderPaletteCss, generatePaletteCss };
|
|
52
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/palette/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAIvD;;;GAGG;AACH,SAAS,gBAAgB,CAAC,OAAgB;IACxC,qDAAqD;IACrD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE;QAC9D,SAAS,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;QACtC,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE;YAC5C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAA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,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QAClD,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE,KAAK;KACd,CAAC,CAAC;IACH,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,kBAAkB,CAAC,UAA6B;IACvD,OAAO,gBAAgB,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["import Color from 'colorjs.io';\nimport { checkName } from './validation.ts';\nimport { generatePalette } from './generatePalette.ts';\nimport type { PaletteDefinition } from '../config/types.ts';\nimport type { PaletteOptions, OklchColor, Palette } from './types.ts';\n\n/**\n * Render a model returned by generatePalette without mutating its raw steps.\n * Gamut mapping happens here, independently of CSS output format.\n */\nfunction renderPaletteCss(palette: Palette): string {\n // const options = normalizeOptions(palette.options);\n const blocks = palette.colors.map(({ name, baseStep, steps }) => {\n checkName(name, 'palette color name');\n const lines = steps.map(({ step, l, c, h }) => {\n if (!Number.isInteger(step) || step < 1 || step > 16) {\n throw new Error('palette step: expected an integer from 1 to 16');\n }\n return ` --${name}-${step}: ${formatColor({ l, c, h }, palette.options)};`;\n });\n if (!Number.isInteger(baseStep) || baseStep < 1 || baseStep > 16) {\n throw new Error('palette baseStep: expected an integer from 1 to 16');\n }\n lines.push(` --${name}: var(--${name}-${baseStep});`);\n return lines.join('\\n');\n });\n return [\n '/* Generated by Argot. */',\n ':root {',\n blocks.join('\\n\\n'),\n '}',\n '',\n ].join('\\n');\n}\n\nfunction formatColor(\n { l, c, h }: OklchColor,\n { format }: PaletteOptions,\n): string {\n if (![l, c, h].every(Number.isFinite)) {\n throw new Error('palette coordinates: expected finite OKLCH values');\n }\n\n const gamut = ['oklch', 'oklab', 'lch', 'lab'].includes(format)\n ? 'p3'\n : 'srgb';\n const color = new Color('oklch', [l, c, h]).toGamut({\n space: gamut,\n method: 'css',\n });\n if (format === 'hex') {\n return color.to('srgb').toString({ format: 'hex', collapse: false });\n }\n return color.to(format).toString({ precision: 6 });\n}\n\nfunction generatePaletteCss(definition: PaletteDefinition): string {\n return renderPaletteCss(generatePalette(definition));\n}\n\nexport { renderPaletteCss, generatePaletteCss };\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
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];
|
|
23
|
+
export interface OklchColor {
|
|
24
|
+
/** Lightness from 0 to 1 */
|
|
25
|
+
l: number;
|
|
26
|
+
c: number;
|
|
27
|
+
h: number;
|
|
28
|
+
}
|
|
29
|
+
export interface NormalizedSeedColor extends OklchColor {
|
|
30
|
+
name: string;
|
|
31
|
+
}
|
|
32
|
+
export interface PaletteStep extends OklchColor {
|
|
33
|
+
/** One-based index, from 1 through 16. */
|
|
34
|
+
step: number;
|
|
35
|
+
}
|
|
36
|
+
export interface PaletteOptions {
|
|
37
|
+
lightnessCurve: LightnessCurveEnum;
|
|
38
|
+
chromaCurve: ChromaCurveEnum;
|
|
39
|
+
format: ColorFormatEnum;
|
|
40
|
+
}
|
|
41
|
+
export interface NormalizedPaletteDefinition {
|
|
42
|
+
version: 1;
|
|
43
|
+
seedColors: NormalizedSeedColor[];
|
|
44
|
+
options: PaletteOptions;
|
|
45
|
+
}
|
|
46
|
+
export interface PaletteScale {
|
|
47
|
+
name: string;
|
|
48
|
+
/** One-based step used for the unnumbered custom-property alias. */
|
|
49
|
+
baseStep: number;
|
|
50
|
+
steps: PaletteStep[];
|
|
51
|
+
}
|
|
52
|
+
/** Raw OKLCH coordinates, before output gamut mapping or rounding. */
|
|
53
|
+
export interface Palette {
|
|
54
|
+
version: 1;
|
|
55
|
+
colors: PaletteScale[];
|
|
56
|
+
options: PaletteOptions;
|
|
57
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
};
|
|
27
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type NormalizedPaletteDefinition, type PaletteOptions, type OklchColor } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Validate a palette definition and return a "normalized" fresh copy with
|
|
4
|
+
* explicit defaults set.
|
|
5
|
+
* Color names must also be unique across all emitted step names and aliases.
|
|
6
|
+
*/
|
|
7
|
+
declare function normalizePaletteDefinition(definition: unknown): NormalizedPaletteDefinition;
|
|
8
|
+
declare function normalizeOptions(options?: unknown): PaletteOptions;
|
|
9
|
+
declare function checkName(name: unknown, field: string): asserts name is string;
|
|
10
|
+
/** Validate numeric seeds without conversion, wrapping, clamping, or rounding. */
|
|
11
|
+
declare function checkCoordinates(value: Record<string, unknown>, field: string): asserts value is Record<string, unknown> & OklchColor;
|
|
12
|
+
export { normalizePaletteDefinition, normalizeOptions, checkName, checkCoordinates, };
|