{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "layer",
  "type": "registry:ui",
  "title": "<ui-layer>",
  "description": "Carbon `Layer` (`cds-layer`): a zone at one level of the layering model. Fields, menus, borders and hover/selected fills inside it use that level's layer set of the current theme (white: level 0 #f4f4f4, the page's own; level 1 #ffffff; level 2 #f4f4f4), so a field on a tile stays distinguishable from the tile: on a tile, use level 1. 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/shared-element",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/layer/layer-shift.styles.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/layer/layer-shift.styles.ts",
      "content": "import { css } from 'lit';\n\n/** Generated by scripts/build-themes.mjs — contextual tokens re-pointed to the layer set of each level. */\nexport const layerShiftStyles = css`\n    :host([level='0']) {\n        --ui-surface-1: var(--ui-layer-1);\n        --ui-surface-2: var(--ui-layer-selected-1);\n        --ui-hairline: var(--ui-border-subtle-1);\n        --ui-hairline-strong: var(--ui-border-strong-1);\n        --ui-ink-subtle: var(--ui-border-strong-1);\n        --ui-ghost-hover: var(--ui-layer-hover-1);\n        --ui-ghost-active: var(--ui-layer-active-1);\n        --ui-layer-background: var(--ui-layer-background-1);\n        --ui-layer-selected-hover: var(--ui-layer-selected-hover-1);\n        --ui-layer-accent: var(--ui-layer-accent-1);\n        --ui-layer-accent-hover: var(--ui-layer-accent-hover-1);\n        --ui-layer-accent-active: var(--ui-layer-accent-active-1);\n        --ui-border-subtle-selected: var(--ui-border-subtle-selected-1);\n        --ui-border-tile: var(--ui-border-tile-1);\n        --ui-row-divider: var(--ui-row-divider-1);\n        --ui-card-background: var(--ui-card-background-1);\n    }\n\n    :host([level='1']) {\n        --ui-surface-1: var(--ui-layer-2);\n        --ui-surface-2: var(--ui-layer-selected-2);\n        --ui-hairline: var(--ui-border-subtle-2);\n        --ui-hairline-strong: var(--ui-border-strong-2);\n        --ui-ink-subtle: var(--ui-border-strong-2);\n        --ui-ghost-hover: var(--ui-layer-hover-2);\n        --ui-ghost-active: var(--ui-layer-active-2);\n        --ui-layer-background: var(--ui-layer-background-2);\n        --ui-layer-selected-hover: var(--ui-layer-selected-hover-2);\n        --ui-layer-accent: var(--ui-layer-accent-2);\n        --ui-layer-accent-hover: var(--ui-layer-accent-hover-2);\n        --ui-layer-accent-active: var(--ui-layer-accent-active-2);\n        --ui-border-subtle-selected: var(--ui-border-subtle-selected-2);\n        --ui-border-tile: var(--ui-border-tile-2);\n        --ui-row-divider: var(--ui-row-divider-2);\n        --ui-card-background: var(--ui-card-background-2);\n    }\n\n    :host([level='2']) {\n        --ui-surface-1: var(--ui-layer-3);\n        --ui-surface-2: var(--ui-layer-selected-3);\n        --ui-hairline: var(--ui-border-subtle-3);\n        --ui-hairline-strong: var(--ui-border-strong-3);\n        --ui-ink-subtle: var(--ui-border-strong-3);\n        --ui-ghost-hover: var(--ui-layer-hover-3);\n        --ui-ghost-active: var(--ui-layer-active-3);\n        --ui-layer-background: var(--ui-layer-background-3);\n        --ui-layer-selected-hover: var(--ui-layer-selected-hover-3);\n        --ui-layer-accent: var(--ui-layer-accent-3);\n        --ui-layer-accent-hover: var(--ui-layer-accent-hover-3);\n        --ui-layer-accent-active: var(--ui-layer-accent-active-3);\n        --ui-border-subtle-selected: var(--ui-border-subtle-selected-3);\n        --ui-border-tile: var(--ui-border-tile-3);\n        --ui-row-divider: var(--ui-row-divider-3);\n        --ui-card-background: var(--ui-card-background-3);\n    }\n`;\n"
    },
    {
      "path": "src/primitives/layer/layer.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/layer/layer.ts",
      "content": "import { css, html, type PropertyValues } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { layerShiftStyles } from './layer-shift.styles.ts';\nimport { UiElement } from '../shared/element.ts';\n\nconst MAX_LEVEL = 2;\n\n/**\n * Carbon `Layer` (`cds-layer`): a zone at one level of the layering model. Fields, menus, borders and\n * hover/selected fills inside it use that level's layer set of the current theme (white: level 0 #f4f4f4, the page's\n * own; level 1 #ffffff; level 2 #f4f4f4), so a field on a tile stays distinguishable from the tile: on a tile, use level 1.\n *\n * `level` 0 = the page's own set (same as outside any layer), 1 and 2 go deeper. As Carbon's `cds-layer`, a layer\n * outside any other is level 0 and one nested in another gets the parent's level + 1 (capped at 2); set `level`\n * to override; a later change of a layer's level reaches the automatic levels inside (as Carbon React's context and\n * `cds-layer`'s `updated`). (Carbon React's `<Layer>`, and the React `Layer` here, start at 1.)\n * The shift is part of this element's own styles, so a layer works inside any shadow root. Theme zones\n * (`data-theme`) are document-level rules in tokens.css: inside a shadow root of your own, adopt tokens.css there too.\n *\n * @slot - Content\n * @csspart base - The wrapper\n * @cssprop --ui-layer-border / --ui-layer-radius - With `with-background`: its border and corner radius (default none, 0: Carbon's square, unbordered zone, Kanok too)\n */\n@customElement('ui-layer')\nexport class UiLayer extends UiElement {\n    static override readonly styles = [\n        layerShiftStyles,\n        css`\n            :host {\n                display: block;\n            }\n\n            /* Carbon layer-background: the level below's colour, so the fields and tiles inside (this level's set) stand out from it */\n            :host([with-background]) {\n                background-color: var(--ui-layer-background);\n                /* Carbon: a square, unbordered zone; a design can frame it as a card (--ui-layer-border, --ui-layer-radius) */\n                border: var(--ui-layer-border, none);\n                border-radius: var(--ui-layer-radius, 0);\n            }\n        `,\n    ];\n\n    /** 0, 1 or 2. Computed from the nearest ancestor layer when not set. */\n    @property({ type: Number, reflect: true })\n    get level() {\n        return this.ownLevel;\n    }\n\n    set level(value: number) {\n        const old = this.ownLevel;\n        this.ownLevel = value;\n        this.levelSet = true; // as an attribute or a property (React sets the property before connecting)\n        this.requestUpdate('level', old);\n    }\n\n    private ownLevel = 0;\n    private levelSet = false;\n\n    /** Paint the layer with Carbon's `layer-background` (`withBackground`): the colour its content sits on (white theme, level 1: #f4f4f4 under #ffffff fields). */\n    @property({ type: Boolean, reflect: true, attribute: 'with-background' }) withBackground = false;\n\n    /** An automatic level follows the layer around it (also called by a layer whose level changed); a set one stays. */\n    syncLevel() {\n        if (this.levelSet) return;\n        const old = this.ownLevel;\n        this.ownLevel = Math.min(parentLevel(this) + 1, MAX_LEVEL);\n        this.requestUpdate('level', old);\n    }\n\n    override connectedCallback() {\n        super.connectedCallback();\n        this.syncLevel();\n    }\n\n    protected override updated(changed: PropertyValues<this>) {\n        super.updated(changed);\n        // a new level: the layers inside, in document order (each reads the one around it)\n        if (changed.has('level')) for (const layer of this.querySelectorAll('ui-layer')) layer.syncLevel();\n    }\n\n    override render() {\n        return html`<slot part=\"base\"></slot>`;\n    }\n}\n\n/** Level of the closest `<ui-layer>` above `el` (through shadow roots), or -1 at the page root. */\nexport function parentLevel(el: Element): number {\n    let node: Node | null = el.parentNode;\n    while (node) {\n        if (node instanceof UiLayer) return node.level;\n        node = node instanceof ShadowRoot ? node.host : node.parentNode;\n    }\n    return -1;\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-layer': UiLayer;\n    }\n}\n"
    }
  ]
}
