sparkle-design-cli 1.1.1 → 1.1.2
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/lib/generate-css.js +15 -54
- package/package.json +8 -5
package/lib/generate-css.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
|
+
import { oklch } from 'culori';
|
|
6
7
|
|
|
7
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
9
|
const __dirname = path.dirname(__filename);
|
|
@@ -188,67 +189,27 @@ function hexToRgba(hex) {
|
|
|
188
189
|
*/
|
|
189
190
|
function hexToOklch(hex) {
|
|
190
191
|
// #を削除
|
|
191
|
-
|
|
192
|
+
const cleanHex = hex.replace('#', '');
|
|
192
193
|
|
|
193
194
|
// 3桁の場合は6桁に拡張
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
.map((char) => char + char)
|
|
198
|
-
.join('');
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const r = parseInt(hex.substring(0, 2), 16) / 255;
|
|
202
|
-
const g = parseInt(hex.substring(2, 4), 16) / 255;
|
|
203
|
-
const b = parseInt(hex.substring(4, 6), 16) / 255;
|
|
195
|
+
const fullHex = cleanHex.length === 3
|
|
196
|
+
? cleanHex.split('').map(char => char + char).join('')
|
|
197
|
+
: cleanHex;
|
|
204
198
|
|
|
205
|
-
//
|
|
206
|
-
|
|
207
|
-
return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const linearR = srgbToLinear(r);
|
|
211
|
-
const linearG = srgbToLinear(g);
|
|
212
|
-
const linearB = srgbToLinear(b);
|
|
213
|
-
|
|
214
|
-
// Linear RGBからXYZ(D65)への変換
|
|
215
|
-
const x = linearR * 0.4124564 + linearG * 0.3575761 + linearB * 0.1804375;
|
|
216
|
-
const y = linearR * 0.2126729 + linearG * 0.7151522 + linearB * 0.0721750;
|
|
217
|
-
const z = linearR * 0.0193339 + linearG * 0.1191920 + linearB * 0.9503041;
|
|
218
|
-
|
|
219
|
-
// XYZからOKLabへの変換
|
|
220
|
-
function f(t) {
|
|
221
|
-
const c1 = 0.8359375; // 3^3/29^3
|
|
222
|
-
const c2 = 0.2109375; // 1/3^3
|
|
223
|
-
const c3 = 29 / (6 ** 3); // 29/6^3
|
|
199
|
+
// culoriを使用してHEXからOKLCHに変換
|
|
200
|
+
const oklchColor = oklch(`#${fullHex}`);
|
|
224
201
|
|
|
225
|
-
|
|
202
|
+
if (!oklchColor) {
|
|
203
|
+
console.warn(`⚠️ 色の変換に失敗しました: ${hex}`);
|
|
204
|
+
return `oklch(0 0 0)`;
|
|
226
205
|
}
|
|
227
206
|
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
const fL = f(l);
|
|
233
|
-
const fM = f(m);
|
|
234
|
-
const fS = f(s);
|
|
235
|
-
|
|
236
|
-
const L = 0.2104542553 * fL + 0.7936177850 * fM - 0.0040720468 * fS;
|
|
237
|
-
const a = 1.9779984951 * fL - 2.4285922050 * fM + 0.4505937099 * fS;
|
|
238
|
-
const b_lab = 0.0259040371 * fL + 0.7827717662 * fM - 0.8086757660 * fS;
|
|
239
|
-
|
|
240
|
-
// OKLabからOKLCHへの変換
|
|
241
|
-
const lightness = L;
|
|
242
|
-
const chroma = Math.sqrt(a * a + b_lab * b_lab);
|
|
243
|
-
let hue = Math.atan2(b_lab, a) * 180 / Math.PI;
|
|
244
|
-
if (hue < 0) hue += 360;
|
|
245
|
-
|
|
246
|
-
// 精度を調整して出力(少数点以下4桁で丸める)
|
|
247
|
-
const l_rounded = Math.round(lightness * 10000) / 10000;
|
|
248
|
-
const c_rounded = Math.round(chroma * 10000) / 10000;
|
|
249
|
-
const h_rounded = chroma < 0.0001 ? 0 : Math.round(hue * 10) / 10;
|
|
207
|
+
// 精度を調整して出力
|
|
208
|
+
const l = Math.round((oklchColor.l || 0) * 10000) / 10000;
|
|
209
|
+
const c = Math.round((oklchColor.c || 0) * 10000) / 10000;
|
|
210
|
+
const h = oklchColor.h ? Math.round(oklchColor.h * 10) / 10 : 0;
|
|
250
211
|
|
|
251
|
-
return `oklch(${
|
|
212
|
+
return `oklch(${l} ${c} ${h})`;
|
|
252
213
|
}
|
|
253
214
|
|
|
254
215
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sparkle-design-cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Sparkle Design CSS Generator - デザインシステムCSSを設定ファイルから生成するツール",
|
|
5
5
|
"main": "lib/generate-css.js",
|
|
6
6
|
"type": "module",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"author": "Goodpatch Inc. <sparkle-design@goodpatch.com>",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"
|
|
27
|
+
"@eslint/js": "^8.57.0",
|
|
28
28
|
"eslint": "^8.57.0",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
29
|
+
"power-assert": "^1.6.1",
|
|
30
|
+
"prettier": "^3.2.5"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"bin/",
|
|
@@ -35,5 +35,8 @@
|
|
|
35
35
|
"templates/",
|
|
36
36
|
"README.md",
|
|
37
37
|
"LICENSE"
|
|
38
|
-
]
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"culori": "^4.0.2"
|
|
41
|
+
}
|
|
39
42
|
}
|