{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shared-position",
  "type": "registry:lib",
  "title": "shared/position",
  "description": "Internal module shared by the ui-* components (position). 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-popup",
    "@kanok-ui/core-position",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/shared/position.ts",
      "type": "registry:lib",
      "target": "components/ui/primitives/shared/position.ts",
      "content": "/**\n * Positions a top-layer floating element (list, menu, calendar, tooltip, toggletip) next to its anchor.\n *\n * The floating element is `position: absolute` in the top layer, so its coordinates are document\n * coordinates and it scrolls with the page in the same frame — no one-frame lag / jitter, which is\n * what `position: fixed` + a scroll listener produces. This is Floating UI's default strategy and\n * what flatpickr (Carbon's date picker) does. core/popup `trackAnchor` re-places it whenever its anchor\n * moves otherwise (a scrolling ancestor, a layout shift, the visual viewport).\n */\n\nimport { css } from 'lit';\nimport { caretOffset, type Placement, type Side } from '../../core/position.ts';\nimport { placePopup, type PlaceOptions } from '../../core/popup.ts';\n\nexport type { Align, Placement, Side } from '../../core/position.ts';\n\n/**\n * Places `floating` (position: absolute, top layer) beside `anchor` with core/popup `placePopup`: flipped to the\n * opposite side when it doesn't fit (keeping its side while open), shifted along the anchor inside the viewport,\n * hidden while the anchor is out of view, and with `size` the room on its side written as `--ui-available-height` /\n * `-width` for its max-height. Start/end follow the text direction. Returns the side actually used.\n */\nexport function placeFloating(anchor: Element, floating: HTMLElement, placement: Placement, gap = 8, options: Omit<PlaceOptions, 'gap'> = {}): Side {\n    return placePopup(anchor, floating, placement, { ...options, gap }).side;\n}\n\n/**\n * `placeFloating` plus a caret (Carbon popover): writes `data-side` on the floating element and\n * `--_caret-pos`, the distance along the edge facing the anchor to the anchor's centre, for `caretStyles`.\n */\nexport function placeWithCaret(anchor: Element, floating: HTMLElement, placement: Placement, gap: number): Side {\n    const side = placeFloating(anchor, floating, placement, gap);\n    floating.dataset.side = side;\n    floating.style.setProperty('--_caret-pos', `${caretOffset(anchor.getBoundingClientRect(), floating.getBoundingClientRect(), side)}px`);\n    return side;\n}\n\n/**\n * The caret of a floating box (`.bubble[data-side]` from `placeWithCaret`): a triangle of the box's own\n * background, 12×6 by default (Carbon `popover-caret-width/height`), overridable with `--_caret-w/h`.\n */\nexport const caretStyles = css`\n    .caret {\n        position: absolute;\n        width: var(--_caret-w, 12px);\n        height: var(--_caret-h, 6px);\n        background: inherit;\n        pointer-events: none;\n    }\n\n    .bubble[data-side='top'] .caret {\n        top: 100%;\n        left: calc(var(--_caret-pos) - var(--_caret-w, 12px) / 2);\n        clip-path: polygon(0 0, 100% 0, 50% 100%);\n    }\n\n    .bubble[data-side='bottom'] .caret {\n        bottom: 100%;\n        left: calc(var(--_caret-pos) - var(--_caret-w, 12px) / 2);\n        clip-path: polygon(50% 0, 100% 100%, 0 100%);\n    }\n\n    .bubble[data-side='left'] .caret,\n    .bubble[data-side='right'] .caret {\n        top: calc(var(--_caret-pos) - var(--_caret-w, 12px) / 2);\n        width: var(--_caret-h, 6px);\n        height: var(--_caret-w, 12px);\n    }\n\n    .bubble[data-side='left'] .caret {\n        left: 100%;\n        clip-path: polygon(0 0, 100% 50%, 0 100%);\n    }\n\n    .bubble[data-side='right'] .caret {\n        right: 100%;\n        clip-path: polygon(100% 0, 0 50%, 100% 100%);\n    }\n`;\n"
    }
  ]
}
