@designbasekorea/ui 0.2.18 → 0.2.19
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/dist/index.esm.js +26 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +26 -8
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +26 -8
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -5287,8 +5287,16 @@
|
|
|
5287
5287
|
const [alpha, setAlpha] = React.useState(100);
|
|
5288
5288
|
const [colorFormat, setColorFormat] = React.useState('hex');
|
|
5289
5289
|
const [isCopied, setIsCopied] = React.useState(false);
|
|
5290
|
-
const [inputValue, setInputValue] = React.useState(defaultValue);
|
|
5290
|
+
const [inputValue, setInputValue] = React.useState(value || defaultValue);
|
|
5291
5291
|
const pickerRef = React.useRef(null);
|
|
5292
|
+
// 초기화: defaultValue가 있으면 HSL 값으로 변환
|
|
5293
|
+
React.useEffect(() => {
|
|
5294
|
+
const initialColor = value || defaultValue;
|
|
5295
|
+
if (initialColor) {
|
|
5296
|
+
updateHSLFromHex(initialColor);
|
|
5297
|
+
setInputValue(initialColor);
|
|
5298
|
+
}
|
|
5299
|
+
}, []); // 컴포넌트 마운트 시에만 실행
|
|
5292
5300
|
// value prop이 변경되면 업데이트
|
|
5293
5301
|
React.useEffect(() => {
|
|
5294
5302
|
if (value) {
|
|
@@ -5315,7 +5323,7 @@
|
|
|
5315
5323
|
b: parseInt(result[3], 16)
|
|
5316
5324
|
} : null;
|
|
5317
5325
|
};
|
|
5318
|
-
// RGB를 HSL로 변환
|
|
5326
|
+
// RGB를 HSL로 변환 (정밀도 개선)
|
|
5319
5327
|
const rgbToHsl = (r, g, b) => {
|
|
5320
5328
|
r /= 255;
|
|
5321
5329
|
g /= 255;
|
|
@@ -5337,9 +5345,14 @@
|
|
|
5337
5345
|
break;
|
|
5338
5346
|
}
|
|
5339
5347
|
}
|
|
5340
|
-
|
|
5348
|
+
// 정밀도 개선: 반올림 대신 더 정확한 계산
|
|
5349
|
+
return {
|
|
5350
|
+
h: Math.round(h * 360 * 100) / 100,
|
|
5351
|
+
s: Math.round(s * 100 * 100) / 100,
|
|
5352
|
+
l: Math.round(l * 100 * 100) / 100
|
|
5353
|
+
};
|
|
5341
5354
|
};
|
|
5342
|
-
// HSL을 RGB로 변환
|
|
5355
|
+
// HSL을 RGB로 변환 (정밀도 개선)
|
|
5343
5356
|
const hslToRgb = (h, s, l) => {
|
|
5344
5357
|
l /= 100;
|
|
5345
5358
|
const a = s * Math.min(l, 1 - l) / 100;
|
|
@@ -5350,10 +5363,14 @@
|
|
|
5350
5363
|
};
|
|
5351
5364
|
return { r: f(0), g: f(8), b: f(4) };
|
|
5352
5365
|
};
|
|
5353
|
-
// HSL을 HEX로 변환
|
|
5366
|
+
// HSL을 HEX로 변환 (정밀도 개선)
|
|
5354
5367
|
const hslToHex = (h, s, l) => {
|
|
5355
5368
|
const rgb = hslToRgb(h, s, l);
|
|
5356
|
-
const toHex = (n) =>
|
|
5369
|
+
const toHex = (n) => {
|
|
5370
|
+
// RGB 값을 0-255 범위로 제한하고 HEX로 변환
|
|
5371
|
+
const clamped = Math.max(0, Math.min(255, Math.round(n)));
|
|
5372
|
+
return clamped.toString(16).padStart(2, '0');
|
|
5373
|
+
};
|
|
5357
5374
|
return `#${toHex(rgb.r)}${toHex(rgb.g)}${toHex(rgb.b)}`.toUpperCase();
|
|
5358
5375
|
};
|
|
5359
5376
|
// 현재 포맷에 따른 색상 문자열 반환
|
|
@@ -5426,8 +5443,9 @@
|
|
|
5426
5443
|
setInputValue(newValue);
|
|
5427
5444
|
// HEX 값이 유효하면 실시간으로 색상 업데이트
|
|
5428
5445
|
if (/^#[0-9A-F]{6}$/i.test(newValue)) {
|
|
5429
|
-
|
|
5430
|
-
|
|
5446
|
+
const normalizedHex = newValue.toUpperCase();
|
|
5447
|
+
handleColorChange(normalizedHex);
|
|
5448
|
+
updateHSLFromHex(normalizedHex);
|
|
5431
5449
|
}
|
|
5432
5450
|
};
|
|
5433
5451
|
// 입력 필드에서 포커스 아웃 시 검증 및 적용
|