@diskette/palette 0.19.0 → 0.20.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/README.md +90 -70
- package/dist/cli/cli.d.ts +1 -1
- package/dist/cli/cli.js +59 -9
- package/dist/colors/amber.d.ts +26 -14
- package/dist/colors/amber.js +130 -114
- package/dist/colors/blue.d.ts +26 -14
- package/dist/colors/blue.js +130 -114
- package/dist/colors/bronze.d.ts +26 -14
- package/dist/colors/bronze.js +130 -114
- package/dist/colors/brown.d.ts +26 -14
- package/dist/colors/brown.js +130 -114
- package/dist/colors/crimson.d.ts +26 -14
- package/dist/colors/crimson.js +130 -114
- package/dist/colors/cyan.d.ts +26 -14
- package/dist/colors/cyan.js +130 -114
- package/dist/colors/gold.d.ts +26 -14
- package/dist/colors/gold.js +130 -114
- package/dist/colors/grass.d.ts +26 -14
- package/dist/colors/grass.js +130 -114
- package/dist/colors/gray.d.ts +26 -14
- package/dist/colors/gray.js +130 -114
- package/dist/colors/green.d.ts +26 -14
- package/dist/colors/green.js +130 -114
- package/dist/colors/indigo.d.ts +26 -14
- package/dist/colors/indigo.js +130 -114
- package/dist/colors/iris.d.ts +26 -14
- package/dist/colors/iris.js +130 -114
- package/dist/colors/jade.d.ts +26 -14
- package/dist/colors/jade.js +130 -114
- package/dist/colors/lime.d.ts +26 -14
- package/dist/colors/lime.js +130 -114
- package/dist/colors/mauve.d.ts +26 -14
- package/dist/colors/mauve.js +130 -114
- package/dist/colors/mint.d.ts +26 -14
- package/dist/colors/mint.js +130 -114
- package/dist/colors/olive.d.ts +26 -14
- package/dist/colors/olive.js +130 -114
- package/dist/colors/orange.d.ts +26 -14
- package/dist/colors/orange.js +130 -114
- package/dist/colors/pink.d.ts +26 -14
- package/dist/colors/pink.js +130 -114
- package/dist/colors/plum.d.ts +26 -14
- package/dist/colors/plum.js +130 -114
- package/dist/colors/purple.d.ts +26 -14
- package/dist/colors/purple.js +130 -114
- package/dist/colors/red.d.ts +26 -14
- package/dist/colors/red.js +130 -114
- package/dist/colors/ruby.d.ts +26 -14
- package/dist/colors/ruby.js +130 -114
- package/dist/colors/sage.d.ts +26 -14
- package/dist/colors/sage.js +130 -114
- package/dist/colors/sand.d.ts +26 -14
- package/dist/colors/sand.js +130 -114
- package/dist/colors/sky.d.ts +26 -14
- package/dist/colors/sky.js +130 -114
- package/dist/colors/slate.d.ts +26 -14
- package/dist/colors/slate.js +130 -114
- package/dist/colors/teal.d.ts +26 -14
- package/dist/colors/teal.js +130 -114
- package/dist/colors/tomato.d.ts +26 -14
- package/dist/colors/tomato.js +130 -114
- package/dist/colors/violet.d.ts +26 -14
- package/dist/colors/violet.js +130 -114
- package/dist/colors/yellow.d.ts +26 -14
- package/dist/colors/yellow.js +130 -114
- package/dist/css.d.ts +1 -0
- package/dist/css.js +26 -8
- package/dist/index.d.ts +808 -436
- package/dist/index.js +1 -1
- package/dist/types.d.ts +20 -16
- package/dist/utils.d.ts +9 -1
- package/dist/utils.js +44 -8
- package/package.json +4 -3
- package/dist/cli/commands/generate.d.ts +0 -54
- package/dist/cli/commands/generate.js +0 -86
- package/dist/cli/commands/list.d.ts +0 -48
- package/dist/cli/commands/list.js +0 -33
package/dist/index.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -4,28 +4,32 @@ export declare const accentColors: readonly ["gray", "gold", "bronze", "brown",
|
|
|
4
4
|
export type AccentColor = (typeof accentColors)[number];
|
|
5
5
|
export type Color = AccentColor | GrayColor;
|
|
6
6
|
type Tuple<T, N extends number, R extends T[] = []> = R['length'] extends N ? R : Tuple<T, N, [...R, T]>;
|
|
7
|
-
type ScaleSteps = Tuple<string,
|
|
7
|
+
export type ScaleSteps = Tuple<string, 12>;
|
|
8
|
+
export interface ColorScale {
|
|
9
|
+
solid: ScaleSteps;
|
|
10
|
+
alpha: ScaleSteps;
|
|
11
|
+
}
|
|
8
12
|
export interface PaletteColor<C extends Color> {
|
|
9
13
|
name: C;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
contrast: string;
|
|
15
|
+
indicator: number;
|
|
16
|
+
track: number;
|
|
17
|
+
light: {
|
|
18
|
+
srgb: ColorScale;
|
|
19
|
+
p3: ColorScale;
|
|
13
20
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
21
|
+
dark: {
|
|
22
|
+
srgb: ColorScale;
|
|
23
|
+
p3: ColorScale;
|
|
17
24
|
};
|
|
18
|
-
contrast: string;
|
|
19
|
-
indicator: string;
|
|
20
|
-
track: string;
|
|
21
25
|
surface: {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
light: {
|
|
27
|
+
srgb: string;
|
|
28
|
+
p3: string;
|
|
25
29
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
dark: {
|
|
31
|
+
srgb: string;
|
|
32
|
+
p3: string;
|
|
29
33
|
};
|
|
30
34
|
};
|
|
31
35
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AccentColor, GrayColor } from './types.ts';
|
|
2
|
-
export declare function writeFileIfNotExists(path: string, data: string | NodeJS.ArrayBufferView): boolean;
|
|
3
2
|
export declare function getMatchingGrayColor(accentColor: AccentColor): GrayColor;
|
|
4
3
|
export declare const LIGHT_SELECTOR = ":root, .light, .light-theme";
|
|
5
4
|
export declare const DARK_SELECTOR = ".dark, .dark-theme";
|
|
@@ -9,3 +8,12 @@ export declare const toVarName: (key: string) => string;
|
|
|
9
8
|
export declare const formatRule: (selector: string, vars: string[]) => string;
|
|
10
9
|
export declare const formatP3: (selector: string, vars: string[]) => string;
|
|
11
10
|
export declare const formatNestedBlock: (selector: string, vars: string[]) => string;
|
|
11
|
+
/**
|
|
12
|
+
* get package.json content from startDir
|
|
13
|
+
* @param cwd
|
|
14
|
+
* @returns package.json content
|
|
15
|
+
*/
|
|
16
|
+
export declare const getPackageJson: (cwd: string) => {
|
|
17
|
+
pkg: any;
|
|
18
|
+
packageJsonPath: string;
|
|
19
|
+
} | undefined;
|
package/dist/utils.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
writeFileSync(path, data);
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import * as url from 'node:url';
|
|
9
5
|
export function getMatchingGrayColor(accentColor) {
|
|
10
6
|
switch (accentColor) {
|
|
11
7
|
case 'tomato':
|
|
@@ -51,3 +47,43 @@ export const toVarName = (key) => `--${key.replace(/A?(\d+)/, (m, n) => (m.start
|
|
|
51
47
|
export const formatRule = (selector, vars) => `${selector} {\n ${vars.join(';\n ')};\n}`;
|
|
52
48
|
export const formatP3 = (selector, vars) => `@supports (color: color(display-p3 1 1 1)) {\n @media (color-gamut: p3) {\n ${selector} {\n ${vars.join(';\n ')};\n }\n }\n}`;
|
|
53
49
|
export const formatNestedBlock = (selector, vars) => `&:where(${selector}) {\n ${vars.join(';\n ')};\n }`;
|
|
50
|
+
const require = createRequire(import.meta.url);
|
|
51
|
+
/**
|
|
52
|
+
* get package.json content from startDir
|
|
53
|
+
* @param cwd
|
|
54
|
+
* @returns package.json content
|
|
55
|
+
*/
|
|
56
|
+
export const getPackageJson = (cwd) => {
|
|
57
|
+
try {
|
|
58
|
+
const startDir = path.dirname(url.fileURLToPath(cwd));
|
|
59
|
+
const packageJsonPath = findPackageJson(startDir);
|
|
60
|
+
if (packageJsonPath) {
|
|
61
|
+
const pkg = require(packageJsonPath);
|
|
62
|
+
return { pkg, packageJsonPath };
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
// ignore error
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* search package.json from startDir
|
|
73
|
+
* @param startDir
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
const findPackageJson = (startDir) => {
|
|
77
|
+
let currentDir = startDir;
|
|
78
|
+
while (true) {
|
|
79
|
+
const packageJsonPath = path.join(currentDir, 'package.json');
|
|
80
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
81
|
+
return packageJsonPath;
|
|
82
|
+
}
|
|
83
|
+
const parentDir = path.resolve(currentDir, '..');
|
|
84
|
+
if (parentDir === currentDir) {
|
|
85
|
+
return '';
|
|
86
|
+
}
|
|
87
|
+
currentDir = parentDir;
|
|
88
|
+
}
|
|
89
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diskette/palette",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.20.0",
|
|
5
5
|
"bin": {
|
|
6
6
|
"palette": "./dist/cli/cli.js"
|
|
7
7
|
},
|
|
@@ -23,12 +23,13 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"
|
|
27
|
-
"type-flag": "^4.0.2"
|
|
26
|
+
"citty": "^0.1.6"
|
|
28
27
|
},
|
|
29
28
|
"devDependencies": {
|
|
30
29
|
"@changesets/cli": "^2.29.7",
|
|
30
|
+
"@diskette/fs": "^0.17.0",
|
|
31
31
|
"@types/node": "^24.3.0",
|
|
32
|
+
"magicast": "^0.5.1",
|
|
32
33
|
"oxlint": "^1.16.0",
|
|
33
34
|
"oxlint-tsgolint": "^0.2.0",
|
|
34
35
|
"prettier": "^3.6.2",
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
export declare const generate: import("cleye").Command<{
|
|
2
|
-
name: "generate";
|
|
3
|
-
alias: "gen";
|
|
4
|
-
parameters: "[colors]"[];
|
|
5
|
-
flags: {
|
|
6
|
-
accents: {
|
|
7
|
-
type: BooleanConstructor;
|
|
8
|
-
alias: string;
|
|
9
|
-
description: string;
|
|
10
|
-
default: boolean;
|
|
11
|
-
};
|
|
12
|
-
output: {
|
|
13
|
-
type: StringConstructor;
|
|
14
|
-
alias: string;
|
|
15
|
-
description: string;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
help: {
|
|
19
|
-
description: string;
|
|
20
|
-
examples: string[];
|
|
21
|
-
};
|
|
22
|
-
}, {
|
|
23
|
-
command: "generate";
|
|
24
|
-
} & import("type-flag").TypeFlag<{
|
|
25
|
-
accents: {
|
|
26
|
-
type: BooleanConstructor;
|
|
27
|
-
alias: string;
|
|
28
|
-
description: string;
|
|
29
|
-
default: boolean;
|
|
30
|
-
};
|
|
31
|
-
output: {
|
|
32
|
-
type: StringConstructor;
|
|
33
|
-
alias: string;
|
|
34
|
-
description: string;
|
|
35
|
-
};
|
|
36
|
-
} & {
|
|
37
|
-
help: BooleanConstructor;
|
|
38
|
-
}> & {
|
|
39
|
-
_: {
|
|
40
|
-
colors: string | undefined;
|
|
41
|
-
};
|
|
42
|
-
showHelp: (options?: {
|
|
43
|
-
version?: string;
|
|
44
|
-
description?: string;
|
|
45
|
-
usage?: false | string | string[];
|
|
46
|
-
examples?: string | string[];
|
|
47
|
-
render?: (nodes: {
|
|
48
|
-
id?: string;
|
|
49
|
-
type: keyof import("cleye").Renderers;
|
|
50
|
-
data: any;
|
|
51
|
-
}[], renderers: import("cleye").Renderers) => string;
|
|
52
|
-
}) => void;
|
|
53
|
-
showVersion: () => void;
|
|
54
|
-
}>;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { command } from 'cleye';
|
|
2
|
-
import { mkdirSync } from 'node:fs';
|
|
3
|
-
import { resolve } from 'node:path';
|
|
4
|
-
import * as palette from "../../colors/index.js";
|
|
5
|
-
import { css } from "../../css.js";
|
|
6
|
-
import { accentColors, grayColors } from "../../types.js";
|
|
7
|
-
import { writeFileIfNotExists } from "../../utils.js";
|
|
8
|
-
// Combined list of all colors (deduplicated since 'gray' appears in both)
|
|
9
|
-
const allColors = [...new Set([...accentColors, ...grayColors])];
|
|
10
|
-
function parseColors(input, available) {
|
|
11
|
-
if (!input)
|
|
12
|
-
return [];
|
|
13
|
-
if (input === 'all')
|
|
14
|
-
return [...available];
|
|
15
|
-
return input.split(',').filter((c) => available.includes(c));
|
|
16
|
-
}
|
|
17
|
-
export const generate = command({
|
|
18
|
-
name: 'generate',
|
|
19
|
-
alias: 'gen',
|
|
20
|
-
parameters: ['[colors]'],
|
|
21
|
-
flags: {
|
|
22
|
-
accents: {
|
|
23
|
-
type: Boolean,
|
|
24
|
-
alias: 'a',
|
|
25
|
-
description: 'Generate accents.css with semantic accent tokens',
|
|
26
|
-
default: false,
|
|
27
|
-
},
|
|
28
|
-
output: {
|
|
29
|
-
type: String,
|
|
30
|
-
alias: 'o',
|
|
31
|
-
description: 'Output directory',
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
help: {
|
|
35
|
-
description: 'Generate CSS files for color palettes',
|
|
36
|
-
examples: [
|
|
37
|
-
'palette generate blue,red,slate -a -o ./styles',
|
|
38
|
-
'palette gen all -a -o ./styles',
|
|
39
|
-
],
|
|
40
|
-
},
|
|
41
|
-
}, (argv) => {
|
|
42
|
-
if (!argv.flags.output) {
|
|
43
|
-
console.error('Error: --output (-o) is required');
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
46
|
-
const selectedColors = parseColors(argv._.colors, allColors);
|
|
47
|
-
if (selectedColors.length === 0) {
|
|
48
|
-
console.error('No colors selected.');
|
|
49
|
-
console.error('Run "palette list" to see available colors.');
|
|
50
|
-
process.exit(1);
|
|
51
|
-
}
|
|
52
|
-
const outputPath = resolve(process.cwd(), argv.flags.output);
|
|
53
|
-
mkdirSync(outputPath, { recursive: true });
|
|
54
|
-
for (const name of selectedColors) {
|
|
55
|
-
const color = palette[name];
|
|
56
|
-
writeFileIfNotExists(`${outputPath}/${name}.css`, css.palette(color, { schemes: ['light'], alpha: true }));
|
|
57
|
-
writeFileIfNotExists(`${outputPath}/${name}-dark.css`, css.palette(color, { schemes: ['dark'], alpha: true }));
|
|
58
|
-
console.log(` ${name}.css, ${name}-dark.css`);
|
|
59
|
-
}
|
|
60
|
-
writeFileIfNotExists(`${outputPath}/black-alpha.css`, css.alpha(palette.blackAlpha));
|
|
61
|
-
writeFileIfNotExists(`${outputPath}/white-alpha.css`, css.alpha(palette.whiteAlpha));
|
|
62
|
-
console.log(' black-alpha.css, white-alpha.css');
|
|
63
|
-
if (argv.flags.accents) {
|
|
64
|
-
// Partition selected colors: gray is treated as accent, other grayColors are grays
|
|
65
|
-
const selectedAccents = selectedColors.filter((c) => accentColors.includes(c));
|
|
66
|
-
const selectedGrays = selectedColors.filter((c) => c !== 'gray' && grayColors.includes(c));
|
|
67
|
-
const accents = css.accents(selectedAccents);
|
|
68
|
-
const grays = css.grays(selectedGrays, 'diskette-palette');
|
|
69
|
-
writeFileIfNotExists(`${outputPath}/accents.css`, `${accents}\n${grays}`);
|
|
70
|
-
console.log(' accents.css');
|
|
71
|
-
}
|
|
72
|
-
const imports = [
|
|
73
|
-
...(argv.flags.accents ? ['./accents.css'] : []),
|
|
74
|
-
...selectedColors.flatMap((name) => [
|
|
75
|
-
`./${name}.css`,
|
|
76
|
-
`./${name}-dark.css`,
|
|
77
|
-
]),
|
|
78
|
-
'./black-alpha.css',
|
|
79
|
-
'./white-alpha.css',
|
|
80
|
-
]
|
|
81
|
-
.map((path) => `@import '${path}';`)
|
|
82
|
-
.join('\n');
|
|
83
|
-
writeFileIfNotExists(`${outputPath}/index.css`, `${imports}\n\n${css.tailwind(['white', 'black', 'accent', ...selectedColors])}`);
|
|
84
|
-
console.log(' index.css');
|
|
85
|
-
console.log(`\nCSS saved to ${outputPath}`);
|
|
86
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export declare const list: import("cleye").Command<{
|
|
2
|
-
name: "list";
|
|
3
|
-
alias: "ls";
|
|
4
|
-
flags: {
|
|
5
|
-
accent: {
|
|
6
|
-
type: BooleanConstructor;
|
|
7
|
-
description: string;
|
|
8
|
-
default: boolean;
|
|
9
|
-
};
|
|
10
|
-
gray: {
|
|
11
|
-
type: BooleanConstructor;
|
|
12
|
-
description: string;
|
|
13
|
-
default: boolean;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
help: {
|
|
17
|
-
description: string;
|
|
18
|
-
};
|
|
19
|
-
}, {
|
|
20
|
-
command: "list";
|
|
21
|
-
} & import("type-flag").TypeFlag<{
|
|
22
|
-
accent: {
|
|
23
|
-
type: BooleanConstructor;
|
|
24
|
-
description: string;
|
|
25
|
-
default: boolean;
|
|
26
|
-
};
|
|
27
|
-
gray: {
|
|
28
|
-
type: BooleanConstructor;
|
|
29
|
-
description: string;
|
|
30
|
-
default: boolean;
|
|
31
|
-
};
|
|
32
|
-
} & {
|
|
33
|
-
help: BooleanConstructor;
|
|
34
|
-
}> & {
|
|
35
|
-
_: {};
|
|
36
|
-
showHelp: (options?: {
|
|
37
|
-
version?: string;
|
|
38
|
-
description?: string;
|
|
39
|
-
usage?: false | string | string[];
|
|
40
|
-
examples?: string | string[];
|
|
41
|
-
render?: (nodes: {
|
|
42
|
-
id?: string;
|
|
43
|
-
type: keyof import("cleye").Renderers;
|
|
44
|
-
data: any;
|
|
45
|
-
}[], renderers: import("cleye").Renderers) => string;
|
|
46
|
-
}) => void;
|
|
47
|
-
showVersion: () => void;
|
|
48
|
-
}>;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { command } from 'cleye';
|
|
2
|
-
import { accentColors, grayColors } from "../../index.js";
|
|
3
|
-
export const list = command({
|
|
4
|
-
name: 'list',
|
|
5
|
-
alias: 'ls',
|
|
6
|
-
flags: {
|
|
7
|
-
accent: {
|
|
8
|
-
type: Boolean,
|
|
9
|
-
description: 'List only accent colors',
|
|
10
|
-
default: false,
|
|
11
|
-
},
|
|
12
|
-
gray: {
|
|
13
|
-
type: Boolean,
|
|
14
|
-
description: 'List only gray colors',
|
|
15
|
-
default: false,
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
help: {
|
|
19
|
-
description: 'List available colors',
|
|
20
|
-
},
|
|
21
|
-
}, (argv) => {
|
|
22
|
-
const showAll = !argv.flags.accent && !argv.flags.gray;
|
|
23
|
-
if (showAll || argv.flags.accent) {
|
|
24
|
-
console.log('Accent colors:');
|
|
25
|
-
console.log(` ${accentColors.join(', ')}`);
|
|
26
|
-
}
|
|
27
|
-
if (showAll)
|
|
28
|
-
console.log();
|
|
29
|
-
if (showAll || argv.flags.gray) {
|
|
30
|
-
console.log('Gray colors:');
|
|
31
|
-
console.log(` ${grayColors.filter((g) => g !== 'gray').join(', ')}`);
|
|
32
|
-
}
|
|
33
|
-
});
|