{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shared-affixes",
  "type": "registry:lib",
  "title": "shared/affixes",
  "description": "Internal module shared by the ui-* components (affixes). Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "lit@^3.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/shared/affixes.ts",
      "type": "registry:lib",
      "target": "components/ui/primitives/shared/affixes.ts",
      "content": "import { html, nothing } from 'lit';\n\n/**\n * A field's `prefix-text` / `suffix-text` (text input, number input): the widths of `.prefix` /\n * `.suffix` as `--prefix-width` / `--suffix-width` on the input, followed as they change (a font\n * loading late, a new text), so the value never runs under them.\n */\nexport class AffixSizes {\n    private observer?: ResizeObserver;\n\n    /** Call after an update that may have added, changed or removed an affix. */\n    follow(root: ParentNode, input: HTMLElement) {\n        const affixes = root.querySelectorAll<HTMLElement>('.prefix, .suffix');\n        this.observer?.disconnect();\n        if (affixes.length === 0) return;\n        const measure = () => {\n            const width = (selector: string) => {\n                const affix = root.querySelector<HTMLElement>(selector);\n                return affix ? `${affix.getBoundingClientRect().width}px` : '';\n            };\n            input.style.setProperty('--prefix-width', width('.prefix'));\n            input.style.setProperty('--suffix-width', width('.suffix'));\n        };\n        measure(); // before the first paint\n        this.observer ??= new ResizeObserver(measure);\n        for (const affix of affixes) this.observer.observe(affix);\n    }\n\n    disconnect() {\n        this.observer?.disconnect();\n        this.observer = undefined;\n    }\n}\n\n/** The prefix or suffix span (part `prefix` / `suffix`, id `<input id>-<kind>` for aria-describedby); nothing when empty. */\nexport const renderAffix = (inputId: string, kind: 'prefix' | 'suffix', text: string) => (text ? html`<span class=${kind} part=${kind} id=\"${inputId}-${kind}\">${text}</span>` : nothing);\n\n/** aria-describedby: the prefix, the suffix, then the message line. */\nexport function affixDescribedBy(inputId: string, prefixText: string, suffixText: string, messageId: string | undefined) {\n    const ids = [prefixText && `${inputId}-prefix`, suffixText && `${inputId}-suffix`, messageId].filter(Boolean);\n    return ids.length > 0 ? ids.join(' ') : nothing;\n}\n"
    }
  ]
}
