{"version":3,"sources":["../src/hooks/use-adornment-width.ts","../src/components/inputs/Input/Input.tsx"],"names":["useState","useCallback","useEffect","forwardRef","useId","useFieldMode","useInlineEdit","useControllableState","jsx","DisplayValue","InputWrapper","jsxs","cn","inputBaseClasses","inputSizeClasses","dirtyClasses","errorClasses","Field"],"mappings":";;;;;;;;;;;;;AA0BO,SAAS,iBAAA,GAAkE;AAChF,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAIA,eAAS,CAAC,CAAA;AACpC,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAIA,eAA6B,IAAI,CAAA;AAEzD,EAAA,MAAM,GAAA,GAAMC,kBAAY,CAAC,CAAA,KAA0B,QAAQ,CAAC,CAAA,EAAG,EAAE,CAAA;AAEjE,EAAAC,eAAA,CAAU,MAAM;AACd,IAAA,IAAI,CAAC,IAAA,EAAM;AACT,MAAA,QAAA,CAAS,CAAC,CAAA;AAEV,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,OAAO,MAAM,QAAA,CAAS,IAAA,CAAK,qBAAA,GAAwB,KAAK,CAAA;AAC9D,IAAA,IAAA,EAAK;AAEL,IAAA,IAAI,OAAO,mBAAmB,WAAA,EAAa;AAE3C,IAAA,MAAM,QAAA,GAAW,IAAI,cAAA,CAAe,IAAI,CAAA;AACxC,IAAA,QAAA,CAAS,QAAQ,IAAI,CAAA;AAErB,IAAA,OAAO,MAAM,SAAS,UAAA,EAAW;AAAA,EACnC,CAAA,EAAG,CAAC,IAAI,CAAC,CAAA;AAET,EAAA,OAAO,CAAC,KAAK,KAAK,CAAA;AACpB;AClCO,IAAM,KAAA,GAAQC,gBAAA;AAAA,EACnB,CACE;AAAA,IACE,IAAA,GAAO,MAAA;AAAA,IACP,IAAA,GAAO,IAAA;AAAA,IACP,KAAA;AAAA,IACA,KAAA;AAAA,IACA,KAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA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AA,EAAA,EAAK,CAAA,EAAE,YAAA,EAAa;AAAA,GAAA,EACvB,CAAA;AAEJ","file":"chunk-LHNC42J3.cjs","sourcesContent":["import { useCallback, useEffect, useState } from \"react\";\n\n/**\n * Measure an inline adornment so the input can reserve exactly its width.\n *\n * ## Why this exists\n *\n * `leading` / `trailing` render ABSOLUTELY over the input, so they take no\n * space in flow and the input must be padded by hand to keep text clear of\n * them. That padding used to be a fixed `pl-9` / `pr-9` — 36px, sized for a\n * single icon. Any wider adornment ran straight under the value: `leading =\n * \"https://\"` is roughly 50px, so `https://` and `fancy.app` rendered on top of\n * one another.\n *\n * A fixed padding cannot be right for arbitrary content, and these props accept\n * arbitrary content — a currency code, a unit, a protocol, a short label. So\n * the width is measured rather than assumed.\n *\n * Returns `0` until measured (and on the server), which is the signal to keep\n * the old fixed padding as a fallback: an unmeasured render is then no worse\n * than it was before, rather than unpadded.\n *\n * `ResizeObserver` rather than a one-shot read, because the width changes after\n * first paint for reasons the first paint cannot see — a webfont swapping in,\n * the adornment's own content changing, a container query resizing the text.\n */\nexport function useAdornmentWidth(): [(node: HTMLElement | null) => void, number] {\n  const [width, setWidth] = useState(0);\n  const [node, setNode] = useState<HTMLElement | null>(null);\n\n  const ref = useCallback((n: HTMLElement | null) => setNode(n), []);\n\n  useEffect(() => {\n    if (!node) {\n      setWidth(0);\n\n      return;\n    }\n\n    const read = () => setWidth(node.getBoundingClientRect().width);\n    read();\n\n    if (typeof ResizeObserver === \"undefined\") return;\n\n    const observer = new ResizeObserver(read);\n    observer.observe(node);\n\n    return () => observer.disconnect();\n  }, [node]);\n\n  return [ref, width];\n}\n","import { forwardRef, useId } from \"react\";\nimport { cn } from \"../../../utils/cn\";\nimport { useControllableState } from \"../../../hooks/use-controllable-state\";\nimport { useAdornmentWidth } from \"../../../hooks/use-adornment-width\";\nimport { Field } from \"../Field\";\nimport { InputWrapper } from \"../InputWrapper\";\nimport {\n  dirtyClasses,\n  errorClasses,\n  inputBaseClasses,\n  inputSizeClasses,\n} from \"../inputs.utils\";\nimport { useFieldMode } from \"../mode/FieldMode.context\";\nimport { DisplayValue } from \"../mode/DisplayValue\";\nimport { useInlineEdit } from \"../mode/useInlineEdit\";\nimport type { InputProps } from \"./Input.types\";\n\nexport const Input = forwardRef<HTMLInputElement, InputProps>(\n  (\n    {\n      type = \"text\",\n      size = \"md\",\n      dirty,\n      error,\n      label,\n      labelHidden,\n      description,\n      required,\n      disabled,\n      className,\n      id,\n      leading,\n      trailing,\n      prefix,\n      suffix,\n      prefixPosition,\n      suffixPosition,\n      mode,\n      onValueChange,\n      onChange,\n      reveal,\n      revealed,\n      onRevealedChange,\n      revealLabel = \"Show password\",\n      hideLabel = \"Hide password\",\n      ...props\n    },\n    ref,\n  ) => {\n    const autoId = useId();\n    const inputId = id ?? autoId;\n    const resolvedMode = useFieldMode(mode);\n    const { showControl, interactive, enterEdit, exitEdit } = useInlineEdit(resolvedMode, disabled);\n\n    // Measured, not assumed: `leading`/`trailing` take arbitrary content, and a\n    // fixed padding can only ever be right for one width. See\n    // `useAdornmentWidth` for what went wrong with the fixed version.\n    const [leadingRef, leadingWidth] = useAdornmentWidth();\n    const [trailingRef, trailingWidth] = useAdornmentWidth();\n\n    // Only meaningful on a password field: a reveal on an already-visible input\n    // is a button that does nothing.\n    const canReveal = reveal === true && type === \"password\";\n    const [isRevealed, setRevealed] = useControllableState(revealed, false, onRevealedChange);\n    const shown = canReveal && isRevealed;\n    // The rendered type, NOT the declared one — `type` stays \"password\" so the\n    // display-mode masking below and any caller reading props are unaffected.\n    const renderedType = shown ? \"text\" : type;\n\n    const input = !showControl ? (\n      <DisplayValue\n        size={size}\n        interactive={interactive}\n        onActivate={enterEdit}\n        leading={leading ?? prefix}\n        trailing={trailing ?? suffix}\n      >\n        {type === \"password\" ? (props.value ? \"••••••\" : \"\") : (props.value as string | undefined)}\n      </DisplayValue>\n    ) : (\n      <InputWrapper\n        prefix={prefix}\n        suffix={suffix}\n        prefixPosition={prefixPosition}\n        suffixPosition={suffixPosition}\n        size={size}\n      >\n        <div data-react-fancy-input=\"\" className=\"relative flex items-center\">\n          {leading && (\n            <span\n              ref={leadingRef}\n              className=\"pointer-events-none absolute left-3 text-zinc-400 dark:text-zinc-500\"\n            >\n              {leading}\n            </span>\n          )}\n          <input\n            ref={ref}\n            id={inputId}\n            type={renderedType}\n            disabled={disabled}\n            required={required}\n            className={cn(\n              inputBaseClasses,\n              inputSizeClasses[size],\n              dirtyClasses(dirty),\n              errorClasses(error),\n              \"w-full\",\n              // The fixed classes are the PRE-MEASURE fallback only. Once the\n              // adornment is measured, the inline style below overrides them\n              // with its real width -- a fixed 36px is correct for one icon and\n              // wrong for anything wider, which is how `https://` came to\n              // render on top of the value.\n              leading && !leadingWidth && \"pl-9\",\n              (trailing || canReveal) && !trailingWidth && \"pr-9\",\n              className,\n            )}\n            style={{\n              // 12px clears `left-3`/`right-3`; 8px is the gap to the text.\n              ...(leadingWidth ? { paddingLeft: leadingWidth + 20 } : null),\n              ...(trailingWidth ? { paddingRight: trailingWidth + 20 } : null),\n              ...props.style,\n            }}\n            onChange={(e) => {\n              onChange?.(e);\n              onValueChange?.(e.target.value);\n            }}\n            {...props}\n            // Inline click-to-edit: focus on entering edit, return to the display\n            // (and run the host's onBlur) when focus leaves.\n            autoFocus={interactive || props.autoFocus}\n            onBlur={(e) => {\n              props.onBlur?.(e);\n              if (interactive) exitEdit();\n            }}\n          />\n          {canReveal ? (\n            <button\n              type=\"button\"\n              // type=\"button\" is load-bearing: the default is \"submit\", so a\n              // reveal inside a login form would submit it on every click.\n              id={`${inputId}-reveal`}\n              data-react-fancy-reveal=\"\"\n              onClick={() => setRevealed((v) => !v)}\n              disabled={disabled}\n              aria-controls={inputId}\n              aria-pressed={shown}\n              aria-label={shown ? hideLabel : revealLabel}\n              title={shown ? hideLabel : revealLabel}\n              // Not focusable by tab: the field and the submit button are the\n              // path through a login form, and a reveal in between is a stop\n              // most people do not want. Still reachable by click and by\n              // screen readers.\n              tabIndex={-1}\n              className=\"absolute right-2 inline-flex items-center justify-center rounded p-1 text-zinc-400 transition-colors hover:text-zinc-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40 disabled:cursor-not-allowed disabled:opacity-50 dark:text-zinc-500 dark:hover:text-zinc-300\"\n            >\n              {shown ? <EyeOffIcon /> : <EyeIcon />}\n            </button>\n          ) : (\n            trailing && (\n              <span\n                ref={trailingRef}\n                className=\"pointer-events-none absolute right-3 text-zinc-400 dark:text-zinc-500\"\n              >\n                {trailing}\n              </span>\n            )\n          )}\n        </div>\n      </InputWrapper>\n    );\n\n    if (label || error || description) {\n      return (\n        <Field\n          label={label}\n          labelHidden={labelHidden}\n          description={description}\n          error={error}\n          required={required}\n          htmlFor={inputId}\n          size={size}\n        >\n          {input}\n        </Field>\n      );\n    }\n\n    return input;\n  },\n);\n\nInput.displayName = \"Input\";\n\n/**\n * Inline SVGs rather than the Icon component: Input is the most-installed\n * primitive in the kit, and routing it through the icon registry would make\n * every consumer's password field depend on an icon set being configured.\n */\nfunction EyeIcon() {\n  return (\n    <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d=\"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0\" />\n      <circle cx=\"12\" cy=\"12\" r=\"3\" />\n    </svg>\n  );\n}\n\nfunction EyeOffIcon() {\n  return (\n    <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d=\"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49\" />\n      <path d=\"M14.084 14.158a3 3 0 0 1-4.242-4.242\" />\n      <path d=\"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143\" />\n      <path d=\"m2 2 20 20\" />\n    </svg>\n  );\n}\n"]}