{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "core-css-grid",
  "type": "registry:lib",
  "title": "core/css-grid",
  "description": "Framework-free behaviour shared by the ui-* components (css-grid); 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/css-grid.ts",
      "type": "registry:lib",
      "target": "components/ui/core/css-grid.ts",
      "content": "/**\n * Carbon's 2x CSS Grid (@carbon/grid `css-grid`): the breakpoints and how a column's span / start / end settle at\n * each of them. `columnLayouts` replays Carbon's stylesheet: every class a Carbon `Column` gets, in the order Carbon\n * writes them (spans, then breakpoint spans, then percent spans, then starts / ends, then breakpoint starts / ends),\n * each active from its breakpoint up — the last active one wins, as in the cascade.\n */\n\nexport type GridBreakpoint = 'sm' | 'md' | 'lg' | 'xlg' | 'max';\n\nexport interface GridBreakpointSpec {\n    name: GridBreakpoint;\n    /** Min viewport width in rem (16px), as Carbon's media queries. */\n    minRem: number;\n    columns: number;\n    /** The grid's inline padding (px). */\n    margin: number;\n}\n\nexport const GRID_BREAKPOINTS: readonly GridBreakpointSpec[] = [\n    { name: 'sm', minRem: 0, columns: 4, margin: 0 },\n    { name: 'md', minRem: 42, columns: 8, margin: 16 },\n    { name: 'lg', minRem: 66, columns: 16, margin: 16 },\n    { name: 'xlg', minRem: 82, columns: 16, margin: 16 },\n    { name: 'max', minRem: 99, columns: 16, margin: 24 },\n];\n\n/** The grid's max width (the max breakpoint's), its gutter and the condensed gutter (px). */\nexport const GRID_MAX_WIDTH = 1584;\nexport const GRID_GUTTER = 32;\nexport const GRID_GUTTER_CONDENSED = 1;\n\nexport type ColumnPercent = '25%' | '50%' | '75%' | '100%';\n\n/** One breakpoint of a column (Carbon `Column` `sm` … `max`): a span, a percent, `true` (auto), or span + offset / start / end. */\nexport type ColumnSpan = boolean | number | ColumnPercent | { span?: number | ColumnPercent; offset?: number; start?: number; end?: number };\n\nexport type ColumnSpans = Partial<Record<GridBreakpoint | 'span', ColumnSpan>>;\n\n/** Where a column sits at one breakpoint: grid-column-start / -end, hidden (span 0), and the columns a subgrid in it gets. */\nexport interface ColumnLayout {\n    start: string;\n    end: string;\n    hidden: boolean;\n    /** Carbon `--cds-grid-columns` on the column; undefined = the column sets none (a subgrid inherits the grid's). */\n    columns?: number;\n}\n\ninterface Declarations {\n    start?: string;\n    end?: string;\n    display?: 'none' | 'block';\n    columns?: number;\n}\n\ninterface Rule {\n    /** The first breakpoint (index) it applies at. */\n    from: number;\n    set: Declarations;\n}\n\nconst MAX_COLUMNS = 16;\nconst PERCENTS: Record<ColumnPercent, number> = { '25%': 0.25, '50%': 0.5, '75%': 0.75, '100%': 1 };\nconst isPercent = (value: unknown): value is ColumnPercent => typeof value === 'string' && value in PERCENTS;\n\n/** Carbon -column-span($i): 0 hides the column, N spans N (and sets the columns of a subgrid inside). */\nfunction spanDeclarations(n: number): Declarations {\n    return n === 0 ? { display: 'none' } : { display: 'block', columns: n, start: `span ${n}`, end: `span ${n}` };\n}\n\n/** A percent span: all columns, or that share of the breakpoint's columns. */\nfunction percentDeclarations(percent: ColumnPercent, columns: number): Declarations {\n    if (percent === '100%') return { start: '1', end: '-1' };\n    const n = columns * PERCENTS[percent];\n    return { columns: n, start: `span ${n}`, end: `span ${n}` };\n}\n\n/** The span part of a breakpoint value (Carbon `bp:col-span-*`), if Carbon has that class. */\nfunction breakpointSpanRules(value: ColumnSpan | undefined, at: number): Declarations | undefined {\n    if (value === undefined || value === false) return undefined;\n    if (value === true) return { start: 'auto', end: 'auto' };\n    const span = typeof value === 'object' ? value.span : value;\n    if (isPercent(span)) return percentDeclarations(span, GRID_BREAKPOINTS[at].columns);\n    // Carbon only writes bp:col-span-N up to that breakpoint's column count\n    if (typeof span === 'number' && span >= 0 && span <= GRID_BREAKPOINTS[at].columns) return spanDeclarations(span);\n    return undefined;\n}\n\n/** The start / end part of a value (Carbon `col-start-*` / `col-end-*`; an offset N starts at N + 1). */\nfunction edgeDeclarations(value: ColumnSpan | undefined): Declarations | undefined {\n    if (typeof value !== 'object' || value === null) return undefined;\n    const set: Declarations = {};\n    if (typeof value.offset === 'number') set.start = value.offset > 0 ? String(value.offset + 1) : 'auto';\n    if (typeof value.start === 'number') set.start = value.start ? String(value.start) : 'auto';\n    if (typeof value.end === 'number') set.end = String(value.end);\n    return set.start === undefined && set.end === undefined ? undefined : set;\n}\n\nfunction rulesOf(spans: ColumnSpans): Rule[] {\n    const rules: Rule[] = [];\n    const add = (from: number, set: Declarations | undefined) => {\n        if (set) rules.push({ from, set });\n    };\n    const base = spans.span;\n    const baseSpan = typeof base === 'object' ? base.span : base;\n    // .col-span-N\n    if (typeof baseSpan === 'number' && baseSpan >= 0 && baseSpan <= MAX_COLUMNS) add(0, spanDeclarations(baseSpan));\n    // .bp:col-span-* (each breakpoint's block, in order)\n    GRID_BREAKPOINTS.forEach((bp, i) => { add(i, breakpointSpanRules(spans[bp.name], i)); });\n    // .col-span-auto / -100 / -75 / -50 / -25 (percents follow each breakpoint's columns)\n    if (baseSpan === true) add(0, { start: 'auto', end: 'auto' });\n    if (isPercent(baseSpan)) GRID_BREAKPOINTS.forEach((bp, i) => { add(i, percentDeclarations(baseSpan, bp.columns)); });\n    // .col-start-* / .col-end-*, then each breakpoint's\n    add(0, edgeDeclarations(base));\n    GRID_BREAKPOINTS.forEach((bp, i) => { add(i, edgeDeclarations(spans[bp.name])); });\n    return rules;\n}\n\n/** Where a Carbon column sits at each breakpoint. */\nexport function columnLayouts(spans: ColumnSpans): Record<GridBreakpoint, ColumnLayout> {\n    const rules = rulesOf(spans);\n    const result = {} as Record<GridBreakpoint, ColumnLayout>;\n    GRID_BREAKPOINTS.forEach((bp, i) => {\n        const now: Declarations = {};\n        for (const rule of rules) if (rule.from <= i) Object.assign(now, rule.set);\n        result[bp.name] = { start: now.start ?? 'auto', end: now.end ?? 'auto', hidden: now.display === 'none', columns: now.columns };\n    });\n    return result;\n}\n\n/**\n * A column attribute as Carbon's web components write it: `\"4\"`, `\"50%\"`, `\"\"` (auto), or tokens\n * `\"span:4 start:3\"`, `\"span:2 end:9\"`, `\"offset:2 span:4\"`. Anything else is ignored.\n */\nexport function parseColumnSpan(value: string | null | undefined): ColumnSpan | undefined {\n    if (value === null || value === undefined) return undefined;\n    const text = value.trim();\n    if (text === '' || text === 'auto' || text === 'true') return true;\n    if (/^\\d+$/.test(text)) return Number(text);\n    if (isPercent(text)) return text;\n    const placed: { span?: number | ColumnPercent; offset?: number; start?: number; end?: number } = {};\n    for (const token of text.split(/\\s+/)) {\n        const [key, raw] = token.split(':');\n        if (key === 'span' && isPercent(raw)) placed.span = raw;\n        else if ((key === 'span' || key === 'offset' || key === 'start' || key === 'end') && /^\\d+$/.test(raw ?? '')) placed[key] = Number(raw);\n    }\n    return Object.keys(placed).length ? placed : undefined;\n}\n"
    }
  ]
}
