{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "grid",
  "type": "registry:ui",
  "title": "<ui-grid>",
  "description": "Carbon 2x Grid (`Grid` / `cds-grid`, CSS Grid mode): 4 / 8 / 16 columns at sm / md (672px) / lg (1056px) and up, 32px gutters (each column 16px in on both sides), the grid 16px in from its edges (0 on small screens, 24px from 1584px), at most 1584px wide and centred. `narrow` hangs the columns' text on the gutter (no start gutter), `condensed` 1px gutters; `full-width` drops the max width; `align=\"start\" | \"end\"` pins it to a side; `with-row-gap` spaces rows like columns. A grid inside a `<ui-column>` is a subgrid of that column's span. 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-css-grid",
    "@kanok-ui/shared-element",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/grid/column-hang.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/grid/column-hang.ts",
      "content": "import { css, html } from 'lit';\nimport { customElement } from 'lit/decorators.js';\nimport { UiElement } from '../shared/element.ts';\n\n/**\n * Carbon `ColumnHang` (`cds-column-hang`): content inside a narrow or condensed column that lines up with the text of\n * wide columns (pushed in by the hang: 16px narrow, 15.5px condensed, none wide).\n *\n * @slot - The content\n */\n@customElement('ui-column-hang')\nexport class UiColumnHang extends UiElement {\n    static override readonly styles = css`\n        :host {\n            display: block;\n            margin-inline-start: var(--ui-grid-column-hang);\n        }\n\n        :host(:dir(rtl)) {\n            margin-inline: initial var(--ui-grid-column-hang);\n        }\n    `;\n\n    override render() {\n        return html`<slot></slot>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-column-hang': UiColumnHang;\n    }\n}\n"
    },
    {
      "path": "src/primitives/grid/column.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/grid/column.ts",
      "content": "import { unsafeCSS, css, html, type PropertyValues } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { GRID_BREAKPOINTS, parseColumnSpan, columnLayouts, type ColumnSpans } from '../../core/css-grid.ts';\nimport { UiElement } from '../shared/element.ts';\n\n/** `@media (min-width: …)` around `rules` for every breakpoint above sm (sm needs none). */\nfunction perBreakpoint(rules: (name: string) => string) {\n    return GRID_BREAKPOINTS.map((bp) => (bp.minRem === 0 ? rules(bp.name) : `@media (min-width: ${bp.minRem}rem) { ${rules(bp.name)} }`)).join('\\n');\n}\n\n/** A column's place at each breakpoint, from the custom properties it sets on itself (see UiColumn.updated). */\nconst columnPlacement = unsafeCSS(\n    perBreakpoint(\n        (bp) => `:host {\n            display: var(--_ui-col-display-${bp}, block);\n            grid-column-start: var(--_ui-col-start-${bp}, auto);\n            grid-column-end: var(--_ui-col-end-${bp}, auto);\n        }\n        :host([data-columns-${bp}]) {\n            --ui-grid-columns: var(--_ui-col-columns-${bp});\n        }`,\n    ),\n);\n\n/**\n * Carbon `Column` (`cds-column`): a grid item, `sm` `md` `lg` `xlg` `max` setting its span from that breakpoint up —\n * a number (`lg=\"4\"`, 0 hides it), a percent of the grid (`\"25%\"` … `\"100%\"`), empty for auto, or tokens\n * `\"span:4 start:3\"`, `\"span:2 end:9\"`, `\"offset:2 span:4\"`; `span` for every breakpoint. Placement settles as in\n * Carbon's stylesheet (core/css-grid). A `<ui-grid>` inside becomes a subgrid of its span.\n *\n * @slot - The column's content\n */\n@customElement('ui-column')\nexport class UiColumn extends UiElement {\n    static override readonly styles = [\n        columnPlacement,\n        css`\n            :host {\n                --ui-grid-mode-start: var(--ui-grid-gutter-start);\n                --ui-grid-mode-end: var(--ui-grid-gutter-end);\n                margin-inline: var(--ui-grid-gutter-start) var(--ui-grid-gutter-end);\n            }\n\n            :host(:dir(rtl)) {\n                margin-inline: var(--ui-grid-gutter-end) var(--ui-grid-gutter-start);\n            }\n        `,\n    ];\n\n    @property({ reflect: true }) sm?: string;\n\n    @property({ reflect: true }) md?: string;\n\n    @property({ reflect: true }) lg?: string;\n\n    @property({ reflect: true }) xlg?: string;\n\n    @property({ reflect: true }) max?: string;\n\n    /** The span at every breakpoint (Carbon `span`). */\n    @property({ reflect: true }) span?: string;\n\n    protected override updated(changed: PropertyValues<this>) {\n        super.updated(changed);\n        const spans: ColumnSpans = { span: parseColumnSpan(this.span) };\n        for (const bp of GRID_BREAKPOINTS) spans[bp.name] = parseColumnSpan(this[bp.name]);\n        const layouts = columnLayouts(spans);\n        for (const bp of GRID_BREAKPOINTS) {\n            const layout = layouts[bp.name];\n            this.style.setProperty(`--_ui-col-start-${bp.name}`, layout.start);\n            this.style.setProperty(`--_ui-col-end-${bp.name}`, layout.end);\n            this.style.setProperty(`--_ui-col-display-${bp.name}`, layout.hidden ? 'none' : 'block');\n            // a subgrid inside takes the column's span where it sets one, else the grid's columns (inherited)\n            if (layout.columns === undefined) this.style.removeProperty(`--_ui-col-columns-${bp.name}`);\n            else this.style.setProperty(`--_ui-col-columns-${bp.name}`, String(layout.columns));\n            this.toggleAttribute(`data-columns-${bp.name}`, layout.columns !== undefined);\n        }\n    }\n\n    override render() {\n        return html`<slot></slot>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-column': UiColumn;\n    }\n}\n"
    },
    {
      "path": "src/primitives/grid/grid.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/grid/grid.ts",
      "content": "// Its child elements are one per file beside it; this module re-exports them (one entry point).\nimport { unsafeCSS, css, html } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { GRID_BREAKPOINTS, GRID_GUTTER, GRID_MAX_WIDTH, GRID_GUTTER_CONDENSED } from '../../core/css-grid.ts';\nimport { UiElement } from '../shared/element.ts';\nexport * from './column.ts';\nexport * from './column-hang.ts';\n\n/** Carbon `:root` grid settings, per breakpoint: the column count and the grid's margin (on a top-level grid only). */\nconst rootSettings = unsafeCSS(\n    GRID_BREAKPOINTS.map((bp) => {\n        const rule = `.grid { --ui-grid-columns: ${bp.columns}; --ui-grid-margin: ${bp.margin}px; }`;\n        return bp.minRem === 0 ? rule : `@media (min-width: ${bp.minRem}rem) { ${rule} }`;\n    }).join('\\n'),\n);\n\n/**\n * Carbon 2x Grid (`Grid` / `cds-grid`, CSS Grid mode): 4 / 8 / 16 columns at sm / md (672px) / lg (1056px) and up,\n * 32px gutters (each column 16px in on both sides), the grid 16px in from its edges (0 on small screens, 24px from\n * 1584px), at most 1584px wide and centred. `narrow` hangs the columns' text on the gutter (no start gutter),\n * `condensed` 1px gutters; `full-width` drops the max width; `align=\"start\" | \"end\"` pins it to a side;\n * `with-row-gap` spaces rows like columns. A grid inside a `<ui-column>` is a subgrid of that column's span.\n *\n * @slot - `<ui-column>` elements\n * @csspart grid - The grid\n * @cssprop --ui-grid-gutter - The gutter (32px; 1px condensed)\n */\n@customElement('ui-grid')\nexport class UiGrid extends UiElement {\n    static override readonly styles = [\n        rootSettings,\n        css`\n            :host {\n                display: block;\n            }\n\n            .grid {\n                --ui-grid-gutter: ${GRID_GUTTER}px;\n                --ui-grid-gutter-start: calc(var(--ui-grid-gutter) / 2);\n                --ui-grid-gutter-end: calc(var(--ui-grid-gutter) / 2);\n                --ui-grid-column-hang: calc(var(--ui-grid-gutter) / 2);\n                display: grid;\n                grid-template-columns: repeat(var(--ui-grid-columns), minmax(0, 1fr));\n                box-sizing: border-box;\n                inline-size: 100%;\n                max-inline-size: ${GRID_MAX_WIDTH}px;\n                margin-inline: auto;\n                padding-inline: var(--ui-grid-margin);\n            }\n\n            .full-width {\n                max-inline-size: 100%;\n            }\n\n            .grid.narrow {\n                --ui-grid-gutter-start: 0px;\n            }\n\n            .grid.condensed {\n                --ui-grid-gutter: ${GRID_GUTTER_CONDENSED}px;\n                --ui-grid-column-hang: ${(GRID_GUTTER - GRID_GUTTER_CONDENSED) / 2}px;\n            }\n\n            .grid.row-gap {\n                row-gap: var(--ui-grid-gutter);\n            }\n\n            .grid.narrow.row-gap {\n                row-gap: calc(var(--ui-grid-gutter) / 2);\n            }\n\n            .start {\n                margin-inline-start: 0;\n            }\n\n            .end {\n                margin-inline-end: 0;\n            }\n\n            /* a subgrid takes its column's span (--ui-grid-columns) and reaches over the column's gutters */\n            .subgrid {\n                display: grid;\n                grid-template-columns: repeat(var(--ui-grid-columns), minmax(0, 1fr));\n                margin-inline: calc(var(--ui-grid-mode-start) * -1) calc(var(--ui-grid-mode-end) * -1);\n            }\n\n            :host(:dir(rtl)) .subgrid {\n                margin-inline: calc(var(--ui-grid-mode-end) * -1) calc(var(--ui-grid-mode-start) * -1);\n            }\n\n            .subgrid.wide {\n                --ui-grid-gutter-start: ${GRID_GUTTER / 2}px;\n                --ui-grid-gutter-end: ${GRID_GUTTER / 2}px;\n                --ui-grid-column-hang: 0px;\n            }\n\n            .subgrid.narrow {\n                --ui-grid-gutter-start: 0px;\n                --ui-grid-gutter-end: ${GRID_GUTTER / 2}px;\n                --ui-grid-column-hang: ${GRID_GUTTER / 2}px;\n            }\n\n            .subgrid.condensed {\n                --ui-grid-gutter: ${GRID_GUTTER_CONDENSED}px;\n                --ui-grid-gutter-start: ${GRID_GUTTER_CONDENSED / 2}px;\n                --ui-grid-gutter-end: ${GRID_GUTTER_CONDENSED / 2}px;\n                --ui-grid-column-hang: ${(GRID_GUTTER - GRID_GUTTER_CONDENSED) / 2}px;\n            }\n\n            .subgrid.row-gap {\n                row-gap: ${GRID_GUTTER}px;\n            }\n\n            .subgrid.narrow.row-gap {\n                row-gap: ${GRID_GUTTER / 2}px;\n            }\n\n            .subgrid.condensed.row-gap {\n                row-gap: ${GRID_GUTTER_CONDENSED}px;\n            }\n        `,\n    ];\n\n    /** No start gutter: text hangs on the gutter (Carbon narrow). */\n    @property({ type: Boolean, reflect: true }) narrow = false;\n\n    /** 1px gutters (Carbon condensed). */\n    @property({ type: Boolean, reflect: true }) condensed = false;\n\n    /** No max width. */\n    @property({ type: Boolean, reflect: true, attribute: 'full-width' }) fullWidth = false;\n\n    /** Pin a max-width grid to a side (centred by default). */\n    @property({ reflect: true }) align?: 'start' | 'center' | 'end';\n\n    /** Rows spaced like columns. */\n    @property({ type: Boolean, reflect: true, attribute: 'with-row-gap' }) withRowGap = false;\n\n    /** Inside another grid's column: a subgrid. */\n    @state() private subgrid = false;\n\n    override connectedCallback() {\n        super.connectedCallback();\n        this.subgrid = !!this.parentElement?.closest('ui-grid');\n    }\n\n    override render() {\n        let mode = 'wide';\n        if (this.narrow) mode = 'narrow';\n        else if (this.condensed) mode = 'condensed';\n        const classes: Record<string, boolean> = this.subgrid\n            ? { subgrid: true, [mode]: true, 'row-gap': this.withRowGap }\n            : { grid: true, narrow: this.narrow, condensed: !this.narrow && this.condensed, 'full-width': this.fullWidth, start: this.align === 'start', end: this.align === 'end', 'row-gap': this.withRowGap };\n        return html`<div class=${classMap(classes)} part=\"grid\"><slot></slot></div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-grid': UiGrid;\n    }\n}\n"
    }
  ]
}
