{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shared-action-set",
  "type": "registry:lib",
  "title": "shared/action-set",
  "description": "Internal module shared by the ui-* components (action-set). 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/core-action-set",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/shared/action-set.ts",
      "type": "registry:lib",
      "target": "components/ui/primitives/shared/action-set.ts",
      "content": "import { css, unsafeCSS } from 'lit';\nimport { actionSetProblems, actionWidth, willStack, type ActionSetSize } from '../../core/action-set.ts';\n\n/** `actionWidth()`'s flex values as the attribute values the styles below read. */\nconst WIDTH_KEY: Record<string, string> = { '0 0 100%': 'full', '0 1 50%': 'half', '0 1 25%': 'quarter', '1 1 75%': 'rest-75', '1 1 50%': 'rest-50', '1 1 25%': 'rest-25' };\n\n/**\n * Carbon ActionSet styles for the `<ui-button>`s slotted into `container` (a selector in the same shadow root): 64px\n * expressive buttons with their text 16px from the top (48px under `[data-condensed]`), widths from\n * `data-action-width`, 1px separators, a column (primary on top) under `[data-stacked]`. Shared by `<ui-action-set>`\n * and the side panel / tearsheet footers, which slot the buttons themselves (a slot inside another element's slot\n * would hide them from `::slotted`).\n */\nexport const actionSetStyles = (container: string) => {\n    const set = unsafeCSS(container);\n    return css`\n        /* Carbon: full-bleed buttons that touch; --ui-actions-* let a design use ordinary buttons, spaced, at the end */\n        ${set} {\n            display: flex;\n            justify-content: flex-end;\n            gap: var(--ui-actions-gap, normal);\n            padding: var(--ui-actions-padding, 0px);\n            background-color: var(--ui-surface-1);\n        }\n\n        /* a column, primary on top (--ui-actions-stacked-*: a design can keep a wrapping row of ordinary buttons) */\n        ${set}[data-stacked] {\n            flex-direction: var(--ui-actions-stacked-direction, column-reverse);\n            flex-wrap: var(--ui-actions-stacked-wrap, nowrap);\n        }\n\n        ${set} ::slotted(*) {\n            margin: 0;\n            --ui-field-height-lg: 64px;\n            --ui-button-align: var(--ui-actions-button-align, flex-start);\n            --ui-button-padding-top: var(--ui-actions-button-padding-top, var(--ui-space-md));\n        }\n\n        ${set}[data-condensed] ::slotted(*) {\n            --ui-field-height-lg: 48px;\n        }\n\n        /* a column: full width, as tall as a button */\n        ${set} ::slotted([data-action-width='stacked']) {\n            flex: none;\n            inline-size: var(--ui-actions-stacked-width, 100%);\n        }\n\n        ${set} ::slotted([data-action-width='full']) {\n            flex: var(--ui-actions-button-flex, 0 0 100%);\n        }\n\n        ${set} ::slotted([data-action-width='half']) {\n            flex: var(--ui-actions-button-flex, 0 1 50%);\n        }\n\n        ${set} ::slotted([data-action-width='quarter']) {\n            flex: var(--ui-actions-button-flex, 0 1 25%);\n            max-inline-size: 232px;\n        }\n\n        ${set} ::slotted([data-action-width='rest-75']) {\n            flex: var(--ui-actions-button-flex, 1 1 75%);\n        }\n\n        ${set} ::slotted([data-action-width='rest-50']) {\n            flex: var(--ui-actions-button-flex, 1 1 50%);\n        }\n\n        ${set} ::slotted([data-action-width='rest-25']) {\n            flex: var(--ui-actions-button-flex, 1 1 25%);\n        }\n\n        /* a ghost in a row starts 16px in (Carbon) */\n        ${set}:not([data-stacked]) ::slotted([kind='ghost']),\n        ${set}:not([data-stacked]) ::slotted([kind='danger-ghost']) {\n            --ui-button-padding-start: var(--ui-space-md);\n        }\n\n        /* 1px button-separator between neighbours (in a stack, above each lower one), not next to the focused one; the\n           button set's setting (Kanok: none) */\n        ${set}:not([data-stacked]) ::slotted(:not(:first-child):not(:focus-within)) {\n            box-shadow: -1px 0 0 0 var(--ui-button-set-separator, var(--ui-button-separator));\n        }\n\n        ${set}[data-stacked] ::slotted(:not(:last-child):not(:focus-within)) {\n            box-shadow: 0 -1px 0 0 var(--ui-button-set-separator, var(--ui-button-separator));\n        }\n    `;\n};\n\n/** The visible buttons of an actions slot. */\nexport const slottedActions = (slot: HTMLSlotElement) => slot.assignedElements().filter((el): el is HTMLElement => el instanceof HTMLElement && !el.hidden);\n\n/** A button's kind as the set reads it (`variant` too; none is primary). */\nconst kindOf = (button: Element) => button.getAttribute('kind') ?? button.getAttribute('variant') ?? 'primary';\n\n/** The last warning each host gave, so a set warns once per change. */\nconst warned = new WeakMap<Element, string>();\n\n/**\n * Warns on the console when the buttons break Carbon's ActionSet rules (Carbon for IBM Products' `ActionSet` logs\n * \"Invalid prop `actions` supplied to `ActionSet`: …\" on each render), once per change of the problems.\n */\nexport function warnActionProblems(host: Element, buttons: readonly Element[], size: ActionSetSize) {\n    const problems = actionSetProblems(buttons.map(kindOf), size);\n    const message = problems.length > 0 ? `<${host.localName}>: Carbon's ActionSet rules: ${problems.join(', and ')}.` : '';\n    if (message === (warned.get(host) ?? '')) return;\n    warned.set(host, message);\n    if (message) console.warn(message);\n}\n\n/** Lays the buttons out (each one's `data-action-width`, the container's `data-stacked`); returns whether they stack. */\nexport function layoutActions(container: HTMLElement, buttons: readonly HTMLElement[], size: ActionSetSize, disableStacking = false): boolean {\n    const stacking = !disableStacking && willStack(size, buttons.length);\n    container.toggleAttribute('data-stacked', stacking);\n    for (const button of buttons) {\n        const kind = kindOf(button);\n        button.dataset.actionWidth = stacking ? 'stacked' : (WIDTH_KEY[actionWidth(kind, buttons.length, size, false).flex] ?? 'half');\n    }\n    return stacking;\n}\n"
    }
  ]
}
