sparkle-design-cli 1.1.6 → 1.1.7
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 +14 -8
- package/package.json +1 -1
package/lib/generate-css.js
CHANGED
|
@@ -197,14 +197,14 @@ function hexToOklch(hex) {
|
|
|
197
197
|
// #を削除
|
|
198
198
|
const cleanHex = hex.replace('#', '');
|
|
199
199
|
|
|
200
|
-
// 3桁の場合は6桁に拡張
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
200
|
+
// 3桁の場合は6桁に、4桁の場合は8桁に拡張
|
|
201
|
+
let fullHex = cleanHex;
|
|
202
|
+
if (cleanHex.length === 3 || cleanHex.length === 4) {
|
|
203
|
+
fullHex = cleanHex
|
|
204
|
+
.split('')
|
|
205
|
+
.map((char) => char + char)
|
|
206
|
+
.join('');
|
|
207
|
+
}
|
|
208
208
|
|
|
209
209
|
// culoriを使用してHEXからOKLCHに変換
|
|
210
210
|
const oklchColor = oklch(`#${fullHex}`);
|
|
@@ -219,6 +219,12 @@ function hexToOklch(hex) {
|
|
|
219
219
|
const c = Math.round((oklchColor.c || 0) * 10000) / 10000;
|
|
220
220
|
const h = oklchColor.h ? Math.round(oklchColor.h * 10) / 10 : 0;
|
|
221
221
|
|
|
222
|
+
// アルファ値がある場合(1未満の場合のみ出力に追加)
|
|
223
|
+
if (oklchColor.alpha !== undefined && oklchColor.alpha < 1) {
|
|
224
|
+
const a = Math.round(oklchColor.alpha * 10000) / 10000;
|
|
225
|
+
return `oklch(${l} ${c} ${h} / ${a})`;
|
|
226
|
+
}
|
|
227
|
+
|
|
222
228
|
return `oklch(${l} ${c} ${h})`;
|
|
223
229
|
}
|
|
224
230
|
|