tailwind-v3-palette 1.0.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.
Potentially problematic release.
This version of tailwind-v3-palette might be problematic. Click here for more details.
- package/LICENSE +21 -0
- package/README.md +107 -0
- package/README_en.md +108 -0
- package/dist/cli.js +326 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 tkura37
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
[English](README_en.md)
|
|
2
|
+
|
|
3
|
+
# tailwind-v3-palette
|
|
4
|
+
Tailwind CSS v3の設定ファイルからテーマの定義を読み取り、一覧性の高いHTMLカラーパレットを生成するCLIツール
|
|
5
|
+
|
|
6
|
+
## 特徴
|
|
7
|
+
- 設定ファイル内のコメント(`// テーマカラー` など)をセクション見出しに反映します
|
|
8
|
+
- カラーのキー構造に応じてカラーパレットを表示します
|
|
9
|
+
|
|
10
|
+
## 対応する設定ファイル形式
|
|
11
|
+
| ファイル名 | 形式 |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| tailwind.config.js | CommonJS |
|
|
14
|
+
| tailwind.config.cjs | CommonJS |
|
|
15
|
+
| tailwind.config.mjs | ES Modules |
|
|
16
|
+
| tailwind.config.ts | TypeScript |
|
|
17
|
+
|
|
18
|
+
## インストール
|
|
19
|
+
```bash
|
|
20
|
+
npm install -D tailwind-v3-palette
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 使い方
|
|
24
|
+
```bash
|
|
25
|
+
npx tailwind-v3-palette
|
|
26
|
+
```
|
|
27
|
+
または
|
|
28
|
+
```bash
|
|
29
|
+
npx t3p
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
デフォルトでは、プロジェクトルートに`color-palette.html`が出力されます
|
|
33
|
+
|
|
34
|
+
設定ファイルが以下の場合:
|
|
35
|
+
```js
|
|
36
|
+
export default {
|
|
37
|
+
content: ["./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}"],
|
|
38
|
+
theme: {
|
|
39
|
+
extend: {
|
|
40
|
+
colors: {
|
|
41
|
+
// プライマリ(インディゴ)
|
|
42
|
+
primary: {
|
|
43
|
+
DEFAULT: "#6366f1",
|
|
44
|
+
50: "#eef2ff",
|
|
45
|
+
100: "#e0e7ff",
|
|
46
|
+
200: "#c7d2fe",
|
|
47
|
+
300: "#a5b4fc",
|
|
48
|
+
400: "#818cf8",
|
|
49
|
+
500: "#6366f1",
|
|
50
|
+
600: "#4f46e5",
|
|
51
|
+
700: "#4338ca",
|
|
52
|
+
800: "#3730a3",
|
|
53
|
+
900: "#312e81",
|
|
54
|
+
},
|
|
55
|
+
// ボーダーの色
|
|
56
|
+
border: {
|
|
57
|
+
DEFAULT: "#e2e8f0",
|
|
58
|
+
strong: "#cbd5e1",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
// 文字色
|
|
62
|
+
textColor: {
|
|
63
|
+
DEFAULT: "#334155",
|
|
64
|
+
heading: "#0f172a",
|
|
65
|
+
body: "#334155",
|
|
66
|
+
muted: "#94a3b8",
|
|
67
|
+
link: "#6366f1",
|
|
68
|
+
"link-hover": "#4f46e5",
|
|
69
|
+
},
|
|
70
|
+
spacing: {
|
|
71
|
+
xs: "0.25rem",
|
|
72
|
+
sm: "0.5rem",
|
|
73
|
+
md: "1rem",
|
|
74
|
+
lg: "1.5rem",
|
|
75
|
+
xl: "2rem",
|
|
76
|
+
"2xl": "3rem",
|
|
77
|
+
"3xl": "4rem",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
fontFamily: {
|
|
81
|
+
sans: ["Noto Sans JP", "sans-serif"],
|
|
82
|
+
mono: ["JetBrains Mono", "monospace"],
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+

|
|
89
|
+
|
|
90
|
+
## 設定
|
|
91
|
+
`package.json`に`tailwindV3Palette.output`を追加すると、出力先を変更できます
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"tailwindV3Palette": {
|
|
95
|
+
"output": "./styles/color-palette.html"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## 動作環境
|
|
101
|
+
- Node.js 18以上
|
|
102
|
+
|
|
103
|
+
## 注意事項
|
|
104
|
+
- Tailwind CSS v4には対応していません。v3の設定ファイル形式のみサポートしています
|
|
105
|
+
|
|
106
|
+
## ライセンス
|
|
107
|
+
MIT
|
package/README_en.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
[Japanese](README.md)
|
|
2
|
+
|
|
3
|
+
# tailwind-v3-palette
|
|
4
|
+
A CLI tool that reads Tailwind CSS v3 config files and generates a well-organized HTML color palette.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
- Reflects comments in the config file (e.g. `// Theme colors`) as section headings
|
|
8
|
+
- Displays the color palette according to the key structure of the colors
|
|
9
|
+
|
|
10
|
+
## Supported config file formats
|
|
11
|
+
|
|
12
|
+
| File name | Format |
|
|
13
|
+
| --- | --- |
|
|
14
|
+
| tailwind.config.js | CommonJS |
|
|
15
|
+
| tailwind.config.cjs | CommonJS |
|
|
16
|
+
| tailwind.config.mjs | ES Modules |
|
|
17
|
+
| tailwind.config.ts | TypeScript |
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
```bash
|
|
21
|
+
npm install -D tailwind-v3-palette
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
```bash
|
|
26
|
+
npx tailwind-v3-palette
|
|
27
|
+
```
|
|
28
|
+
or
|
|
29
|
+
```bash
|
|
30
|
+
npx t3p
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
By default, `color-palette.html` is generated in the project root.
|
|
34
|
+
|
|
35
|
+
Given the following config file:
|
|
36
|
+
```js
|
|
37
|
+
export default {
|
|
38
|
+
content: ["./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}"],
|
|
39
|
+
theme: {
|
|
40
|
+
extend: {
|
|
41
|
+
colors: {
|
|
42
|
+
// Primary (Indigo)
|
|
43
|
+
primary: {
|
|
44
|
+
DEFAULT: "#6366f1",
|
|
45
|
+
50: "#eef2ff",
|
|
46
|
+
100: "#e0e7ff",
|
|
47
|
+
200: "#c7d2fe",
|
|
48
|
+
300: "#a5b4fc",
|
|
49
|
+
400: "#818cf8",
|
|
50
|
+
500: "#6366f1",
|
|
51
|
+
600: "#4f46e5",
|
|
52
|
+
700: "#4338ca",
|
|
53
|
+
800: "#3730a3",
|
|
54
|
+
900: "#312e81",
|
|
55
|
+
},
|
|
56
|
+
// Border color
|
|
57
|
+
border: {
|
|
58
|
+
DEFAULT: "#e2e8f0",
|
|
59
|
+
strong: "#cbd5e1",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
// Text color
|
|
63
|
+
textColor: {
|
|
64
|
+
DEFAULT: "#334155",
|
|
65
|
+
heading: "#0f172a",
|
|
66
|
+
body: "#334155",
|
|
67
|
+
muted: "#94a3b8",
|
|
68
|
+
link: "#6366f1",
|
|
69
|
+
"link-hover": "#4f46e5",
|
|
70
|
+
},
|
|
71
|
+
spacing: {
|
|
72
|
+
xs: "0.25rem",
|
|
73
|
+
sm: "0.5rem",
|
|
74
|
+
md: "1rem",
|
|
75
|
+
lg: "1.5rem",
|
|
76
|
+
xl: "2rem",
|
|
77
|
+
"2xl": "3rem",
|
|
78
|
+
"3xl": "4rem",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
fontFamily: {
|
|
82
|
+
sans: ["Noto Sans JP", "sans-serif"],
|
|
83
|
+
mono: ["JetBrains Mono", "monospace"],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+

|
|
90
|
+
|
|
91
|
+
## Configuration
|
|
92
|
+
Add `tailwindV3Palette.output` to your `package.json` to change the output path.
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"tailwindV3Palette": {
|
|
96
|
+
"output": "./styles/color-palette.html"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Requirements
|
|
102
|
+
- Node.js 18 or later
|
|
103
|
+
|
|
104
|
+
## Note
|
|
105
|
+
- Tailwind CSS v4 is not supported. Only v3 config file formats are supported.
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
MIT
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import fs3 from "fs";
|
|
5
|
+
import path3 from "path";
|
|
6
|
+
|
|
7
|
+
// src/detect-config.ts
|
|
8
|
+
import fs from "fs";
|
|
9
|
+
import path from "path";
|
|
10
|
+
var CONFIG_FILES = [
|
|
11
|
+
"tailwind.config.ts",
|
|
12
|
+
"tailwind.config.js",
|
|
13
|
+
"tailwind.config.cjs",
|
|
14
|
+
"tailwind.config.mjs"
|
|
15
|
+
];
|
|
16
|
+
function detectConfig(cwd) {
|
|
17
|
+
for (const file of CONFIG_FILES) {
|
|
18
|
+
const filePath = path.join(cwd, file);
|
|
19
|
+
if (fs.existsSync(filePath)) {
|
|
20
|
+
return filePath;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
throw new Error(
|
|
24
|
+
"Tailwind CSS \u306E\u8A2D\u5B9A\u30D5\u30A1\u30A4\u30EB\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002tailwind.config.{ts,js,cjs,mjs} \u306E\u3044\u305A\u308C\u304B\u3092\u4F5C\u6210\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/parse-config.ts
|
|
29
|
+
import { createRequire } from "module";
|
|
30
|
+
import { createJiti } from "jiti";
|
|
31
|
+
import { pathToFileURL } from "url";
|
|
32
|
+
async function parseConfig(filePath) {
|
|
33
|
+
const ext = filePath.slice(filePath.lastIndexOf("."));
|
|
34
|
+
try {
|
|
35
|
+
switch (ext) {
|
|
36
|
+
case ".ts": {
|
|
37
|
+
const jiti = createJiti(filePath);
|
|
38
|
+
const mod = await jiti.import(filePath);
|
|
39
|
+
return extractDefault(mod);
|
|
40
|
+
}
|
|
41
|
+
case ".mjs": {
|
|
42
|
+
const mod = await import(pathToFileURL(filePath).href);
|
|
43
|
+
return extractDefault(mod);
|
|
44
|
+
}
|
|
45
|
+
case ".js":
|
|
46
|
+
case ".cjs": {
|
|
47
|
+
const require2 = createRequire(filePath);
|
|
48
|
+
return require2(filePath);
|
|
49
|
+
}
|
|
50
|
+
default:
|
|
51
|
+
throw new Error(`\u672A\u5BFE\u5FDC\u306E\u62E1\u5F35\u5B50\u3067\u3059: ${ext}`);
|
|
52
|
+
}
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (error instanceof SyntaxError) {
|
|
55
|
+
throw new Error(`\u8A2D\u5B9A\u30D5\u30A1\u30A4\u30EB\u306E\u69CB\u6587\u30A8\u30E9\u30FC: ${error.message}`);
|
|
56
|
+
}
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function extractDefault(mod) {
|
|
61
|
+
return mod?.default ?? mod;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/is-hex-color.ts
|
|
65
|
+
var HEX_COLOR_RE = /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3}([0-9a-fA-F]{2})?)?$/;
|
|
66
|
+
function isHexColor(value) {
|
|
67
|
+
return HEX_COLOR_RE.test(value);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/extract-colors.ts
|
|
71
|
+
function extractColors(theme) {
|
|
72
|
+
const sectionMap = /* @__PURE__ */ new Map();
|
|
73
|
+
function collectSections(obj) {
|
|
74
|
+
for (const [sectionName, sectionValue] of Object.entries(obj)) {
|
|
75
|
+
if (sectionName === "extend") {
|
|
76
|
+
if (isPlainObject(sectionValue)) {
|
|
77
|
+
collectSections(sectionValue);
|
|
78
|
+
}
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (!isPlainObject(sectionValue)) continue;
|
|
82
|
+
const groups = collectGroups(
|
|
83
|
+
sectionName,
|
|
84
|
+
sectionValue
|
|
85
|
+
);
|
|
86
|
+
if (groups.length === 0) continue;
|
|
87
|
+
if (!sectionMap.has(sectionName)) {
|
|
88
|
+
sectionMap.set(sectionName, []);
|
|
89
|
+
}
|
|
90
|
+
sectionMap.get(sectionName).push(...groups);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
collectSections(theme);
|
|
94
|
+
const sections = [];
|
|
95
|
+
for (const [name, groups] of sectionMap) {
|
|
96
|
+
sections.push({ name, groups });
|
|
97
|
+
}
|
|
98
|
+
return sections;
|
|
99
|
+
}
|
|
100
|
+
function collectGroups(sectionName, obj) {
|
|
101
|
+
const groups = [];
|
|
102
|
+
const flatEntries = collectEntries(obj);
|
|
103
|
+
if (flatEntries.length > 0) {
|
|
104
|
+
groups.push({ name: sectionName, entries: flatEntries });
|
|
105
|
+
}
|
|
106
|
+
for (const [groupName, groupValue] of Object.entries(obj)) {
|
|
107
|
+
if (!isPlainObject(groupValue)) continue;
|
|
108
|
+
const entries = collectEntries(groupValue);
|
|
109
|
+
if (entries.length > 0) {
|
|
110
|
+
groups.push({ name: groupName, entries });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return groups;
|
|
114
|
+
}
|
|
115
|
+
function collectEntries(obj) {
|
|
116
|
+
const entries = [];
|
|
117
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
118
|
+
if (typeof value === "string" && isHexColor(value)) {
|
|
119
|
+
entries.push({ key, hex: value });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return entries;
|
|
123
|
+
}
|
|
124
|
+
function isPlainObject(value) {
|
|
125
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/extract-comments.ts
|
|
129
|
+
import ts from "typescript";
|
|
130
|
+
function extractComments(source) {
|
|
131
|
+
const result = /* @__PURE__ */ new Map();
|
|
132
|
+
const sourceFile = ts.createSourceFile(
|
|
133
|
+
"config.ts",
|
|
134
|
+
source,
|
|
135
|
+
ts.ScriptTarget.Latest,
|
|
136
|
+
true
|
|
137
|
+
);
|
|
138
|
+
function visit(node) {
|
|
139
|
+
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name)) {
|
|
140
|
+
const propName = node.name.text;
|
|
141
|
+
if (ts.isObjectLiteralExpression(node.initializer)) {
|
|
142
|
+
const commentText = getLeadingCommentText(node, source);
|
|
143
|
+
if (commentText) {
|
|
144
|
+
result.set(propName, commentText);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
ts.forEachChild(node, visit);
|
|
149
|
+
}
|
|
150
|
+
visit(sourceFile);
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
function getLeadingCommentText(node, source) {
|
|
154
|
+
const ranges = ts.getLeadingCommentRanges(source, node.getFullStart());
|
|
155
|
+
if (!ranges || ranges.length === 0) return void 0;
|
|
156
|
+
const texts = ranges.map((range) => {
|
|
157
|
+
const raw = source.slice(range.pos, range.end);
|
|
158
|
+
if (range.kind === ts.SyntaxKind.SingleLineCommentTrivia) {
|
|
159
|
+
return raw.replace(/^\/\/\s?/, "").trim();
|
|
160
|
+
}
|
|
161
|
+
return raw.replace(/^\/\*\s?/, "").replace(/\s?\*\/$/, "").trim();
|
|
162
|
+
});
|
|
163
|
+
const filtered = texts.filter((t) => t.length > 0);
|
|
164
|
+
return filtered.length > 0 ? filtered.join(" ") : void 0;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/resolve-output.ts
|
|
168
|
+
import fs2 from "fs";
|
|
169
|
+
import path2 from "path";
|
|
170
|
+
var DEFAULT_OUTPUT = "color-palette.html";
|
|
171
|
+
function resolveOutput(cwd) {
|
|
172
|
+
const pkgPath = path2.join(cwd, "package.json");
|
|
173
|
+
if (!fs2.existsSync(pkgPath)) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
"package.json \u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u30EB\u30FC\u30C8\u3067\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
const pkg = JSON.parse(fs2.readFileSync(pkgPath, "utf-8"));
|
|
179
|
+
const output = pkg?.tailwindV3Palette?.output;
|
|
180
|
+
if (typeof output === "string" && output.length > 0) {
|
|
181
|
+
return path2.resolve(cwd, output);
|
|
182
|
+
}
|
|
183
|
+
return path2.resolve(cwd, DEFAULT_OUTPUT);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/detect-layout.ts
|
|
187
|
+
function detectLayout(entries) {
|
|
188
|
+
const numericCount = entries.filter(
|
|
189
|
+
(e) => e.key !== "DEFAULT" && /^\d+$/.test(e.key)
|
|
190
|
+
).length;
|
|
191
|
+
return numericCount >= entries.length / 2 ? "card" : "pair";
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// src/process-default.ts
|
|
195
|
+
function processDefault(entries) {
|
|
196
|
+
const defaultEntry = entries.find((e) => e.key === "DEFAULT");
|
|
197
|
+
if (!defaultEntry) return entries;
|
|
198
|
+
const others = entries.filter((e) => e.key !== "DEFAULT");
|
|
199
|
+
if (others.length === 0) return entries;
|
|
200
|
+
const matchExists = others.some((e) => e.hex === defaultEntry.hex);
|
|
201
|
+
if (!matchExists) return entries.map((e) => ({ ...e }));
|
|
202
|
+
return others.map(
|
|
203
|
+
(e) => e.hex === defaultEntry.hex ? { key: `${e.key} (DEFAULT)`, hex: e.hex } : { ...e }
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// src/generate-html.ts
|
|
208
|
+
function generateHtml(sections) {
|
|
209
|
+
const body = sections.map((section) => {
|
|
210
|
+
const groups = section.groups.map((group) => renderGroup(group)).join("\n");
|
|
211
|
+
return `
|
|
212
|
+
<h2>${section.name}</h2>${groups}`;
|
|
213
|
+
}).join("\n");
|
|
214
|
+
return `<!DOCTYPE html>
|
|
215
|
+
<html lang="ja">
|
|
216
|
+
<head>
|
|
217
|
+
<meta charset="UTF-8">
|
|
218
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
219
|
+
<title>Tailwind Theme Colors</title>
|
|
220
|
+
<style>
|
|
221
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
222
|
+
body { font-family: system-ui, sans-serif; padding: 2rem; background: #f9fafb; color: #1f2937; }
|
|
223
|
+
h1 { font-size: 1.5rem; margin-bottom: 2rem; }
|
|
224
|
+
h2 { font-size: 1.25rem; margin: 2rem 0 0.5rem; color: #111827; border-bottom: 1px solid #e5e7eb; padding-bottom: 0.25rem; }
|
|
225
|
+
h3 { font-size: 1rem; margin: 1.5rem 0 0.5rem; color: #374151; }
|
|
226
|
+
.group { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
|
|
227
|
+
.swatch {
|
|
228
|
+
width: 5rem; text-align: center; border-radius: 0.5rem;
|
|
229
|
+
overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.1);
|
|
230
|
+
}
|
|
231
|
+
.swatch .color { height: 3.5rem; }
|
|
232
|
+
.swatch .label { font-size: 0.75rem; padding: 0.25rem 0; background: #fff; line-height: 1.3; }
|
|
233
|
+
.swatch .label .name { font-weight: 600; }
|
|
234
|
+
.swatch .label .hex { color: #6b7280; }
|
|
235
|
+
.pair { display: inline-flex; gap: 0.5rem; margin-right: 1.5rem; margin-bottom: 0.5rem; align-items: center; }
|
|
236
|
+
.pair .color { width: 2.5rem; height: 2.5rem; border-radius: 0.375rem; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
|
|
237
|
+
.pair .info { font-size: 0.85rem; line-height: 1.4; }
|
|
238
|
+
.pair .info .name { font-weight: 600; }
|
|
239
|
+
.pair .info .hex { color: #6b7280; }
|
|
240
|
+
</style>
|
|
241
|
+
</head>
|
|
242
|
+
<body>
|
|
243
|
+
<h1>Tailwind Theme Color Palette</h1>
|
|
244
|
+
${body}
|
|
245
|
+
</body>
|
|
246
|
+
</html>
|
|
247
|
+
`;
|
|
248
|
+
}
|
|
249
|
+
function renderGroup(group) {
|
|
250
|
+
const entries = processDefault(group.entries);
|
|
251
|
+
const layout = detectLayout(group.entries);
|
|
252
|
+
const heading = group.comment ? `${group.name} (${group.comment})` : group.name;
|
|
253
|
+
if (layout === "card") {
|
|
254
|
+
return renderCardGroup(heading, entries);
|
|
255
|
+
}
|
|
256
|
+
return renderPairGroup(heading, entries);
|
|
257
|
+
}
|
|
258
|
+
function renderCardGroup(heading, entries) {
|
|
259
|
+
const swatches = entries.map(
|
|
260
|
+
(e) => ` <div class="swatch"><div class="color" style="background:${e.hex}"></div><div class="label"><div class="name">${e.key}</div><div class="hex">${e.hex}</div></div></div>`
|
|
261
|
+
).join("\n");
|
|
262
|
+
return `
|
|
263
|
+
<h3>${heading}</h3>
|
|
264
|
+
<div class="group">
|
|
265
|
+
${swatches}
|
|
266
|
+
</div>`;
|
|
267
|
+
}
|
|
268
|
+
function renderPairGroup(heading, entries) {
|
|
269
|
+
const pairs = entries.map((e) => {
|
|
270
|
+
const borderStyle = isLightColor(e.hex) ? " border:1px solid #cbd5e1" : "";
|
|
271
|
+
return ` <div class="pair"><div class="color" style="background:${e.hex};${borderStyle}"></div><div class="info"><div class="name">${e.key}</div><div class="hex">${e.hex}</div></div></div>`;
|
|
272
|
+
}).join("\n");
|
|
273
|
+
return `
|
|
274
|
+
<h3>${heading}</h3>
|
|
275
|
+
<div>
|
|
276
|
+
${pairs}
|
|
277
|
+
</div>`;
|
|
278
|
+
}
|
|
279
|
+
function isLightColor(hex) {
|
|
280
|
+
const normalized = hex.replace("#", "");
|
|
281
|
+
let r, g, b;
|
|
282
|
+
if (normalized.length === 3) {
|
|
283
|
+
r = parseInt(normalized[0] + normalized[0], 16);
|
|
284
|
+
g = parseInt(normalized[1] + normalized[1], 16);
|
|
285
|
+
b = parseInt(normalized[2] + normalized[2], 16);
|
|
286
|
+
} else {
|
|
287
|
+
r = parseInt(normalized.slice(0, 2), 16);
|
|
288
|
+
g = parseInt(normalized.slice(2, 4), 16);
|
|
289
|
+
b = parseInt(normalized.slice(4, 6), 16);
|
|
290
|
+
}
|
|
291
|
+
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
292
|
+
return luminance > 0.85;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// src/index.ts
|
|
296
|
+
async function run(cwd) {
|
|
297
|
+
const configPath = detectConfig(cwd);
|
|
298
|
+
const config = await parseConfig(configPath);
|
|
299
|
+
const theme = config?.theme ?? {};
|
|
300
|
+
const sections = extractColors(theme);
|
|
301
|
+
const source = fs3.readFileSync(configPath, "utf-8");
|
|
302
|
+
const comments = extractComments(source);
|
|
303
|
+
for (const section of sections) {
|
|
304
|
+
for (const group of section.groups) {
|
|
305
|
+
const comment = comments.get(group.name);
|
|
306
|
+
if (comment) {
|
|
307
|
+
group.comment = comment;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const html = generateHtml(sections);
|
|
312
|
+
const outputPath = resolveOutput(cwd);
|
|
313
|
+
const outputDir = path3.dirname(outputPath);
|
|
314
|
+
if (!fs3.existsSync(outputDir)) {
|
|
315
|
+
fs3.mkdirSync(outputDir, { recursive: true });
|
|
316
|
+
}
|
|
317
|
+
fs3.writeFileSync(outputPath, html, "utf-8");
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// src/cli.ts
|
|
321
|
+
run(process.cwd()).then(() => {
|
|
322
|
+
process.exit(0);
|
|
323
|
+
}).catch((error) => {
|
|
324
|
+
console.error(error.message);
|
|
325
|
+
process.exit(1);
|
|
326
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tailwind-v3-palette",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Generate an HTML color palette from Tailwind CSS v3 config files",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/cli.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"tailwind-v3-palette": "dist/cli.js",
|
|
9
|
+
"t3p": "dist/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md",
|
|
14
|
+
"README_en.md"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsup",
|
|
18
|
+
"test": "vitest"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"tailwindcss",
|
|
22
|
+
"tailwind",
|
|
23
|
+
"color-palette",
|
|
24
|
+
"cli"
|
|
25
|
+
],
|
|
26
|
+
"author": "tkura37",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/tkura37/tailwind-v3-palette.git"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18"
|
|
34
|
+
},
|
|
35
|
+
"packageManager": "pnpm@10.28.0",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"tsup": "^8.5.1",
|
|
38
|
+
"vitest": "^4.0.18"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"jiti": "^2.6.1",
|
|
42
|
+
"typescript": "^5.9.3"
|
|
43
|
+
}
|
|
44
|
+
}
|