{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "core-overflow",
  "type": "registry:lib",
  "title": "core/overflow",
  "description": "Framework-free behaviour shared by the ui-* components (overflow); 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/overflow.ts",
      "type": "registry:lib",
      "target": "components/ui/core/overflow.ts",
      "content": "/**\n * How many items of a row fit, the rest going to an overflow menu — Carbon's `createOverflowHandler`\n * (@carbon/utilities, used by the card's header actions), framework-free: the renderer measures,\n * this decides. Sizes include each item's margins plus the row's gap.\n */\nexport interface OverflowInput {\n    /** The space the row has (its client width). */\n    container: number;\n    /** Each item's size, in order. */\n    sizes: readonly number[];\n    /** Items that always stay (e.g. a pinned button). */\n    fixedSizes?: readonly number[];\n    /** The overflow menu button's size, reserved once anything overflows. */\n    offset: number;\n    /** The row's gap; the last item has none after it. */\n    gap?: number;\n    /** At most this many items visible. */\n    maxVisible?: number;\n    /**\n     * Keep the first item even when it doesn't quite fit, so the row is never empty (default; the card's actions). Off,\n     * every item can go (the page header's tags and breadcrumbs, as Carbon's handler: only the overflow is left).\n     */\n    keepFirst?: boolean;\n}\n\nconst sum = (values: readonly number[]) => values.reduce((total, value) => total + value, 0);\n\n/** The number of leading items that stay visible; the rest overflow. Never 0 when there is any room at all. */\nexport function visibleCount({ container, sizes, fixedSizes = [], offset, gap = 0, maxVisible, keepFirst = true }: OverflowInput): number {\n    const cap = maxVisible ?? sizes.length;\n    const trailingGap = sizes.length + fixedSizes.length > 0 ? gap : 0;\n    if (sum(sizes) + sum(fixedSizes) - trailingGap <= container) return Math.min(cap, sizes.length);\n    const available = container - offset - sum(fixedSizes) + gap;\n    let used = 0;\n    let count = 0;\n    while (count < sizes.length && count < cap && used + sizes[count] <= available) {\n        used += sizes[count];\n        count++;\n    }\n    // the first item stays even when it doesn't quite fit, so the row is never empty\n    return keepFirst && count === 0 && sizes.length > 0 && container > 0 ? 1 : count;\n}\n"
    }
  ]
}
