{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "core-action-set",
  "type": "registry:lib",
  "title": "core/action-set",
  "description": "Framework-free behaviour shared by the ui-* components (action-set); no DOM, no lit. 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": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/core/action-set.ts",
      "type": "registry:lib",
      "target": "components/ui/core/action-set.ts",
      "content": "/** Carbon for IBM Products `ActionSet` sizes (a side panel passes its own; xs counts as sm). */\nexport type ActionSetSize = 'sm' | 'md' | 'lg' | 'xl' | '2xl';\n\n/** How wide one button is: its flex, and Carbon's 232px cap for the quarter widths. */\nexport interface ActionWidth {\n    flex: string;\n    maxWidth: string;\n}\n\nconst isGhost = (kind: string | undefined) => kind === 'ghost' || kind === 'danger--ghost' || kind === 'danger-ghost';\n\n/** Carbon's order of kinds: ghosts first and primary last in a row; a stack reverses it (primary on top). */\nconst ORDER: Record<string, number> = { ghost: 1, 'danger--ghost': 2, 'danger-ghost': 2, tertiary: 3, danger: 5, primary: 6 };\nexport const actionOrder = (kind: string | undefined) => ORDER[kind ?? 'primary'] ?? 4;\n\n/** Small sets, and medium ones with more than two actions, stack one per row. */\nexport const willStack = (size: ActionSetSize, count: number) => size === 'sm' || (size === 'md' && count > 2);\n\n/** The actions in Carbon's order (stable, so equal kinds keep theirs). */\nexport function sortActions<T extends { kind?: string }>(actions: readonly T[], stacking: boolean): T[] {\n    return [...actions].sort((a, b) => (actionOrder(a.kind) - actionOrder(b.kind)) * (stacking ? -1 : 1));\n}\n\n/** What Carbon warns about in a set of actions (an empty list when it is fine). */\nexport function actionSetProblems(kinds: readonly (string | undefined)[], size: ActionSetSize): string[] {\n    const count = (match: (kind: string) => boolean) => kinds.filter((k) => match(k ?? 'primary')).length;\n    const stacking = willStack(size, kinds.length);\n    const ghosts = count(isGhost);\n    const problems: string[] = [];\n    if (stacking && kinds.length > 3) problems.push('no more than three actions in this size of ActionSet');\n    if (kinds.length > 4) problems.push('no more than four actions in an ActionSet');\n    if (count((k) => k === 'primary') > 1) problems.push(\"no more than one 'primary' action\");\n    if (ghosts > 1) problems.push(\"no more than one 'ghost' action\");\n    if (stacking && kinds.length > 1 && ghosts > 0) problems.push(\"no 'ghost' action next to others in this size of ActionSet\");\n    if (count((k) => !(k in ORDER) && k !== 'secondary') > 0) problems.push(\"only 'primary', 'secondary', 'tertiary', 'danger', 'ghost' and 'danger--ghost' actions\");\n    return problems;\n}\n\nconst FULL: ActionWidth = { flex: '0 0 100%', maxWidth: 'none' };\nconst HALF: ActionWidth = { flex: '0 1 50%', maxWidth: 'none' };\nconst QUARTER: ActionWidth = { flex: '0 1 25%', maxWidth: '232px' };\n\n/**\n * One button's width in a row of `count` (Carbon ActionSet): a lone button fills a medium set, half a large one, a\n * quarter of an xl one; two take half each in md / lg; three or four take a quarter (232px at most); a ghost takes\n * what the others leave (all of it alone, 75% next to one, 50% next to two, 25% next to three). Stacked: full width.\n */\nexport function actionWidth(kind: string | undefined, count: number, size: ActionSetSize, stacking: boolean): ActionWidth {\n    if (stacking) return FULL;\n    const wide = size === 'xl' || size === '2xl';\n    if (isGhost(kind)) {\n        if (count <= 1) return FULL;\n        return { flex: `1 1 ${{ 2: '75%', 3: '50%' }[count] ?? '25%'}`, maxWidth: 'none' };\n    }\n    if (wide || count >= 4 || (count === 3 && size === 'lg')) return QUARTER;\n    if (count === 1 && size === 'md') return FULL;\n    return HALF;\n}\n"
    }
  ]
}
