{
  "name": "rating",
  "type": "ui:component",
  "title": "Rating",
  "description": "Interactive and readonly star rating control with hover preview and keyboard arrow support.",
  "dependencies": [
    "@lucide/icons"
  ],
  "registryDependencies": [
    "theme",
    "icon"
  ],
  "files": [
    {
      "path": "src/ui/rating.tsx",
      "target": "src/ui/rating.tsx",
      "sha256": "537f31fbcfa71644b9586ba45613fce3c8b9cb7697d62086dc9b2450af387440",
      "content": "import './theme.css';\nimport { Star } from '@lucide/icons';\nimport { scope, type Ctx } from '@fierst/aster';\nimport { Icon } from './icon';\n\nconst rateScope = scope`\n  :scope {\n    display: inline-flex;\n    align-items: center;\n    gap: 0.2rem;\n    font-family: var(--aster-font-sans);\n  }\n  .star-btn {\n    border: none;\n    background: transparent;\n    padding: 0.18rem;\n    border-radius: var(--aster-radius-xs);\n    color: var(--aster-border-strong);\n    display: inline-grid;\n    place-items: center;\n    cursor: pointer;\n    touch-action: manipulation;\n    transition: transform var(--aster-dur-fast) var(--aster-ease-motion), color var(--aster-dur-fast);\n  }\n  .star-btn:hover:not(:disabled) { transform: scale(1.12); }\n  .star-btn:focus-visible { outline: none; box-shadow: var(--aster-focus-ring); }\n  .star-btn:disabled { cursor: default; }\n  .star-btn.is-filled { color: var(--aster-warning); }\n  .star-btn.is-filled svg { fill: currentColor; }\n  .rate-text {\n    margin-left: 0.35rem;\n    font-size: 0.8rem;\n    font-family: var(--aster-font-mono);\n    color: var(--aster-on-surface-muted);\n  }\n`;\n\nexport function* Rating(\n  props: {\n    value?: number;\n    defaultValue?: number;\n    max?: number;\n    size?: number;\n    readOnly?: boolean;\n    showValue?: boolean;\n    label?: string;\n    onChange?: (rating: number) => void;\n    class?: string;\n  },\n  ctx: Ctx,\n) {\n  let internal = props.defaultValue ?? 0;\n  let hovered = 0;\n\n  for (props of ctx) {\n    const max = Math.max(1, Math.trunc(props.max ?? 5));\n    const isControlled = props.value !== undefined;\n    const current = Math.max(0, Math.min(max, Math.round(isControlled ? props.value! : internal)));\n    const display = hovered || current;\n\n    const select = (n: number) => {\n      if (props.readOnly) return;\n      if (!isControlled) internal = n;\n      props.onChange?.(n);\n    };\n\n    const onKeyDown = (e: KeyboardEvent) => {\n      if (props.readOnly) return;\n      const focusRating = (next: number) => {\n        select(next);\n        (e.currentTarget as HTMLElement).querySelectorAll('button')[next - 1]?.focus();\n      };\n      if (e.key === 'ArrowRight' || e.key === 'ArrowUp') {\n        e.preventDefault();\n        focusRating(current >= max ? 1 : current + 1);\n      } else if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') {\n        e.preventDefault();\n        focusRating(current <= 1 ? max : current - 1);\n      }\n    };\n\n    yield (\n      <div\n        role=\"radiogroup\"\n        aria-label={props.label ?? 'Rating'}\n        class={[rateScope, props.class].filter(Boolean).join(' ')}\n        on:pointerleave={() => (hovered = 0)}\n        onKeyDown={onKeyDown}\n      >\n        {Array.from({ length: max }, (_, idx) => {\n          const n = idx + 1;\n          return (\n            <button\n              key={n}\n              type=\"button\"\n              role=\"radio\"\n              tabIndex={n === (current || 1) ? 0 : -1}\n              aria-checked={n === current}\n              aria-label={`${n} of ${max} stars`}\n              disabled={props.readOnly}\n              class=\"star-btn\"\n              class:is-filled={n <= display}\n              on:pointerenter={() => !props.readOnly && (hovered = n)}\n              onClick={() => select(n)}\n            >\n              <Icon icon={Star} size={props.size ?? 18} />\n            </button>\n          );\n        })}\n        {props.showValue ? (\n          <span class=\"rate-text\">\n            {current}/{max}\n          </span>\n        ) : null}\n      </div>\n    );\n  }\n}\n"
    }
  ]
}
