@webdevarif/dashui 0.3.6 → 0.3.8

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.mjs CHANGED
@@ -3237,9 +3237,13 @@ var ColorPicker = ({
3237
3237
  var ColorPickerSelection = memo(({ className, ...props }) => {
3238
3238
  const containerRef = useRef4(null);
3239
3239
  const [isDragging, setIsDragging] = useState7(false);
3240
- const [posX, setPosX] = useState7(0);
3241
- const [posY, setPosY] = useState7(0);
3242
- const { hue, setSaturation, setLightness } = useColorPicker();
3240
+ const { hue, saturation, lightness, setSaturation, setLightness } = useColorPicker();
3241
+ const [posX, setPosX] = useState7(() => saturation / 100);
3242
+ const [posY, setPosY] = useState7(() => {
3243
+ const x = saturation / 100;
3244
+ const topL = x < 0.01 ? 100 : 50 + 50 * (1 - x);
3245
+ return topL > 0 ? Math.max(0, Math.min(1, 1 - lightness / topL)) : 0;
3246
+ });
3243
3247
  const bg = useMemo2(
3244
3248
  () => `linear-gradient(0deg,rgba(0,0,0,1),rgba(0,0,0,0)),linear-gradient(90deg,rgba(255,255,255,1),rgba(255,255,255,0)),hsl(${hue},100%,50%)`,
3245
3249
  [hue]
@@ -3382,42 +3386,88 @@ var ColorPickerEyeDropper = ({ className, ...props }) => {
3382
3386
  };
3383
3387
  var ColorPickerOutput = ({ className, ...props }) => {
3384
3388
  const { mode, setMode } = useColorPicker();
3385
- return /* @__PURE__ */ jsx49(
3386
- "select",
3387
- {
3388
- value: mode,
3389
- onChange: (e) => setMode(e.target.value),
3390
- className: cn(
3391
- "h-7 bg-white/5 border border-white/10 rounded-md text-xs text-white/60 px-1.5 outline-none",
3392
- "hover:border-white/20 focus:border-white/30 cursor-pointer shrink-0",
3393
- className
3394
- ),
3395
- children: ["HEX", "HSL", "RGB"].map((f) => /* @__PURE__ */ jsx49("option", { value: f, className: "bg-[#1a1c2e]", children: f }, f))
3396
- }
3397
- );
3389
+ return /* @__PURE__ */ jsxs33("div", { className: cn("relative shrink-0", className), children: [
3390
+ /* @__PURE__ */ jsx49(
3391
+ "select",
3392
+ {
3393
+ value: mode,
3394
+ onChange: (e) => setMode(e.target.value),
3395
+ className: "appearance-none h-7 bg-white/8 border border-white/10 rounded-md text-xs text-white/70 pl-2 pr-6 outline-none hover:border-white/20 cursor-pointer",
3396
+ style: { backgroundColor: "rgba(255,255,255,0.05)" },
3397
+ children: ["HEX", "HSL", "RGB"].map((f) => /* @__PURE__ */ jsx49("option", { value: f, style: { background: "#1a1c2e" }, children: f }, f))
3398
+ }
3399
+ ),
3400
+ /* @__PURE__ */ jsx49("svg", { className: "pointer-events-none absolute right-1.5 top-1/2 -translate-y-1/2 w-3 h-3 text-white/40", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", children: /* @__PURE__ */ jsx49("path", { d: "m6 9 6 6 6-6" }) })
3401
+ ] });
3398
3402
  };
3399
3403
  var ColorPickerFormat = ({ className, ...props }) => {
3400
- const { hue, saturation, lightness, alpha, mode } = useColorPicker();
3401
- let displayValue = "";
3402
- try {
3403
- const c = Color.hsl(hue, saturation, lightness).alpha(alpha / 100);
3404
- if (mode === "HEX") displayValue = c.hex();
3405
- else if (mode === "HSL") displayValue = `${Math.round(hue)} ${Math.round(saturation)}% ${Math.round(lightness)}%`;
3406
- else if (mode === "RGB") {
3407
- const rgb = c.rgb().array().map(Math.round);
3408
- displayValue = `${rgb[0]}, ${rgb[1]}, ${rgb[2]}`;
3404
+ const { hue, saturation, lightness, alpha, mode, setHue, setSaturation, setLightness, setAlpha } = useColorPicker();
3405
+ const [focused, setFocused] = useState7(false);
3406
+ const [localVal, setLocalVal] = useState7("");
3407
+ const computedVal = (() => {
3408
+ try {
3409
+ const c = Color.hsl(hue, saturation, lightness).alpha(alpha / 100);
3410
+ if (mode === "HEX") return c.hex().toUpperCase();
3411
+ if (mode === "HSL") return `${Math.round(hue)} ${Math.round(saturation)}% ${Math.round(lightness)}%`;
3412
+ if (mode === "RGB") {
3413
+ const [r, g, b] = c.rgb().array().map(Math.round);
3414
+ return `${r}, ${g}, ${b}`;
3415
+ }
3416
+ } catch {
3409
3417
  }
3410
- } catch {
3411
- displayValue = "";
3412
- }
3418
+ return "";
3419
+ })();
3420
+ useEffect5(() => {
3421
+ if (!focused) setLocalVal(computedVal);
3422
+ }, [computedVal, focused]);
3423
+ const tryApply = (raw) => {
3424
+ try {
3425
+ if (mode === "HEX") {
3426
+ const hex = raw.startsWith("#") ? raw : `#${raw}`;
3427
+ const c = Color(hex);
3428
+ setHue(c.hue());
3429
+ setSaturation(c.saturationl());
3430
+ setLightness(c.lightness());
3431
+ setAlpha(c.alpha() * 100);
3432
+ } else if (mode === "HSL") {
3433
+ const parts = raw.split(/[\s,%]+/).filter(Boolean);
3434
+ if (parts.length >= 3) {
3435
+ setHue(+parts[0]);
3436
+ setSaturation(+parts[1]);
3437
+ setLightness(+parts[2]);
3438
+ }
3439
+ } else if (mode === "RGB") {
3440
+ const parts = raw.split(/[\s,]+/).filter(Boolean);
3441
+ if (parts.length >= 3) {
3442
+ const c = Color.rgb(+parts[0], +parts[1], +parts[2]);
3443
+ setHue(c.hue());
3444
+ setSaturation(c.saturationl());
3445
+ setLightness(c.lightness());
3446
+ }
3447
+ }
3448
+ } catch {
3449
+ }
3450
+ };
3413
3451
  return /* @__PURE__ */ jsx49(
3414
3452
  "input",
3415
3453
  {
3416
- readOnly: true,
3417
3454
  type: "text",
3418
- value: displayValue,
3455
+ value: focused ? localVal : computedVal,
3456
+ onChange: (e) => {
3457
+ setLocalVal(e.target.value);
3458
+ tryApply(e.target.value);
3459
+ },
3460
+ onFocus: () => {
3461
+ setFocused(true);
3462
+ setLocalVal(computedVal);
3463
+ },
3464
+ onBlur: () => {
3465
+ tryApply(localVal);
3466
+ setFocused(false);
3467
+ },
3419
3468
  className: cn(
3420
- "flex-1 h-7 bg-white/5 border border-white/10 rounded-md px-2 text-xs text-white/50 font-mono outline-none",
3469
+ "flex-1 min-w-0 h-7 bg-white/5 border border-white/10 rounded-md px-2",
3470
+ "text-xs text-white/70 font-mono outline-none focus:border-white/30",
3421
3471
  className
3422
3472
  ),
3423
3473
  ...props
@@ -3515,7 +3565,7 @@ function HslColorInput({ value, onChange, className, inputClassName, disabled })
3515
3565
  sideOffset: 6,
3516
3566
  align: "start",
3517
3567
  className: cn(
3518
- "z-[9999] rounded-xl shadow-2xl p-3 w-[14rem]",
3568
+ "z-[9999] rounded-xl shadow-2xl p-3 w-[220px]",
3519
3569
  "bg-[#0f1117] border border-white/10",
3520
3570
  "focus:outline-none"
3521
3571
  ),
@@ -3530,9 +3580,9 @@ function HslColorInput({ value, onChange, className, inputClassName, disabled })
3530
3580
  /* @__PURE__ */ jsx50(ColorPickerAlpha, {})
3531
3581
  ] })
3532
3582
  ] }),
3533
- /* @__PURE__ */ jsxs34("div", { className: "flex items-center gap-1.5", children: [
3583
+ /* @__PURE__ */ jsxs34("div", { className: "flex items-center gap-1.5 min-w-0", children: [
3534
3584
  /* @__PURE__ */ jsx50(ColorPickerOutput, {}),
3535
- /* @__PURE__ */ jsx50(ColorPickerFormat, {})
3585
+ /* @__PURE__ */ jsx50(ColorPickerFormat, { className: "min-w-0" })
3536
3586
  ] })
3537
3587
  ] }, hexValue)
3538
3588
  }