{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shared-row-wrap",
  "type": "registry:lib",
  "title": "shared/row-wrap",
  "description": "Internal module shared by the ui-* components (row-wrap). 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-slider",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/shared/row-wrap.ts",
      "type": "registry:lib",
      "target": "components/ui/primitives/shared/row-wrap.ts",
      "content": "import type { ReactiveController, ReactiveControllerHost } from 'lit';\nimport { sliderRowWraps } from '../../core/slider.ts';\n\n/**\n * Watches a flex row whose `flexible` item has a minimum width (a slider's track) and says when the row no longer fits\n * its box at that minimum (`wraps`), so the element can let it wrap. A row that fits keeps Carbon's single line exactly;\n * CSS `flex-wrap` alone would break the line by the items' preferred sizes instead. Re-measures when the box or any\n * item changes size (ResizeObserver), not on every render: in the next frame, so that wrapping (which resizes the\n * items) is no resize inside the observer's own delivery (no \"ResizeObserver loop\" error).\n */\nexport class RowWrapController implements ReactiveController {\n    wraps = false;\n    private observer?: ResizeObserver;\n    private frame = 0;\n    private observed: Element[] = [];\n    private readonly host: ReactiveControllerHost & HTMLElement;\n    private readonly rowSelector: string;\n    private readonly flexibleSelector: string;\n\n    constructor(host: ReactiveControllerHost & HTMLElement, rowSelector: string, flexibleSelector: string) {\n        this.host = host;\n        this.rowSelector = rowSelector;\n        this.flexibleSelector = flexibleSelector;\n        host.addController(this);\n    }\n\n    hostConnected() {\n        if (typeof ResizeObserver === 'undefined') return;\n        this.observer = new ResizeObserver(() => {\n            if (!this.frame) this.frame = requestAnimationFrame(() => this.measure());\n        });\n    }\n\n    hostDisconnected() {\n        cancelAnimationFrame(this.frame);\n        this.frame = 0;\n        this.observer?.disconnect();\n        this.observer = undefined;\n        this.observed = [];\n    }\n\n    hostUpdated() {\n        const row = this.row();\n        if (!row || !this.observer) return;\n        const now = [this.host, ...row.children];\n        if (now.length === this.observed.length && now.every((el, i) => el === this.observed[i])) return;\n        this.observer.disconnect();\n        for (const el of now) this.observer.observe(el);\n        this.observed = now;\n    }\n\n    private row() {\n        return this.host.shadowRoot?.querySelector<HTMLElement>(this.rowSelector) ?? null;\n    }\n\n    private measure() {\n        this.frame = 0;\n        const row = this.row();\n        if (!row) return;\n        const widths = [...row.children].flatMap((el) => {\n            const style = getComputedStyle(el);\n            if (style.display === 'none') return [];\n            const margins = Number.parseFloat(style.marginInlineStart) + Number.parseFloat(style.marginInlineEnd);\n            const width = el.matches(this.flexibleSelector) ? Number.parseFloat(style.minInlineSize) || 0 : el.getBoundingClientRect().width;\n            return [width + margins];\n        });\n        const wraps = sliderRowWraps(widths, Number.parseFloat(getComputedStyle(row).columnGap) || 0, row.clientWidth);\n        if (wraps === this.wraps) return;\n        this.wraps = wraps;\n        this.host.requestUpdate();\n    }\n}\n"
    }
  ]
}
