{
  "$schema": "https://uipkge.dev/schema/registry-item.json",
  "name": "hexbin-map",
  "title": "Hexbin Map",
  "type": "registry:ui",
  "description": "React mirror of @uipkge/hexbin-map — see the Vue registry item for the canonical description.",
  "categories": [
    "chart"
  ],
  "files": [
    {
      "path": "packages/elements-lit/src/components/charts/hexbin-map.ts",
      "content": "import { LitElement, css, html } from 'lit'\nimport { styleMap } from 'lit/directives/style-map.js'\nimport { Globe } from 'lucide'\nimport { tailwind } from '../../lib/styles'\nimport { ThemeController } from '../../lib/theme'\nimport { icon } from '../../lib/icon'\nimport { cn } from '../../lib/utils'\nimport { heightToStyle } from './lib/chart-theme'\nimport { defaultTrue } from './lib/chart-element'\nimport '../map/map'\n\nexport interface HexState {\n  id: string\n  name: string\n  col: number\n  row: number\n}\n\nexport interface HexbinDatum {\n  value: number\n  status?: 'leader' | 'active' | 'growing' | 'developing' | 'neutral'\n  description?: string\n  color?: string\n}\n\nexport const US_HEX_STATES: HexState[] = [\n  { id: 'AK', name: 'Alaska', col: 0, row: 0 },\n  { id: 'ME', name: 'Maine', col: 11, row: 0 },\n  { id: 'WA', name: 'Washington', col: 1, row: 1 },\n  { id: 'ID', name: 'Idaho', col: 2, row: 1 },\n  { id: 'MT', name: 'Montana', col: 3, row: 1 },\n  { id: 'ND', name: 'North Dakota', col: 4, row: 1 },\n  { id: 'MN', name: 'Minnesota', col: 5, row: 1 },\n  { id: 'IL', name: 'Illinois', col: 6, row: 1 },\n  { id: 'WI', name: 'Wisconsin', col: 7, row: 1 },\n  { id: 'MI', name: 'Michigan', col: 8, row: 1 },\n  { id: 'NY', name: 'New York', col: 9, row: 1 },\n  { id: 'VT', name: 'Vermont', col: 10, row: 1 },\n  { id: 'NH', name: 'New Hampshire', col: 11, row: 1 },\n  { id: 'OR', name: 'Oregon', col: 1, row: 2 },\n  { id: 'NV', name: 'Nevada', col: 2, row: 2 },\n  { id: 'WY', name: 'Wyoming', col: 3, row: 2 },\n  { id: 'SD', name: 'South Dakota', col: 4, row: 2 },\n  { id: 'IA', name: 'Iowa', col: 5, row: 2 },\n  { id: 'IN', name: 'Indiana', col: 6, row: 2 },\n  { id: 'OH', name: 'Ohio', col: 7, row: 2 },\n  { id: 'PA', name: 'Pennsylvania', col: 8, row: 2 },\n  { id: 'NJ', name: 'New Jersey', col: 9, row: 2 },\n  { id: 'MA', name: 'Massachusetts', col: 10, row: 2 },\n  { id: 'RI', name: 'Rhode Island', col: 11, row: 2 },\n  { id: 'CA', name: 'California', col: 1, row: 3 },\n  { id: 'UT', name: 'Utah', col: 2, row: 3 },\n  { id: 'CO', name: 'Colorado', col: 3, row: 3 },\n  { id: 'NE', name: 'Nebraska', col: 4, row: 3 },\n  { id: 'MO', name: 'Missouri', col: 5, row: 3 },\n  { id: 'KY', name: 'Kentucky', col: 6, row: 3 },\n  { id: 'WV', name: 'West Virginia', col: 7, row: 3 },\n  { id: 'VA', name: 'Virginia', col: 8, row: 3 },\n  { id: 'MD', name: 'Maryland', col: 9, row: 3 },\n  { id: 'DE', name: 'Delaware', col: 10, row: 3 },\n  { id: 'AZ', name: 'Arizona', col: 2, row: 4 },\n  { id: 'NM', name: 'New Mexico', col: 3, row: 4 },\n  { id: 'KS', name: 'Kansas', col: 4, row: 4 },\n  { id: 'AR', name: 'Arkansas', col: 5, row: 4 },\n  { id: 'TN', name: 'Tennessee', col: 6, row: 4 },\n  { id: 'NC', name: 'North Carolina', col: 7, row: 4 },\n  { id: 'SC', name: 'South Carolina', col: 8, row: 4 },\n  { id: 'DC', name: 'District of Columbia', col: 9, row: 4 },\n  { id: 'CT', name: 'Connecticut', col: 10, row: 4 },\n  { id: 'OK', name: 'Oklahoma', col: 4, row: 5 },\n  { id: 'LA', name: 'Louisiana', col: 5, row: 5 },\n  { id: 'MS', name: 'Mississippi', col: 6, row: 5 },\n  { id: 'AL', name: 'Alabama', col: 7, row: 5 },\n  { id: 'GA', name: 'Georgia', col: 8, row: 5 },\n  { id: 'HI', name: 'Hawaii', col: 0, row: 6 },\n  { id: 'TX', name: 'Texas', col: 4, row: 6 },\n  { id: 'FL', name: 'Florida', col: 8, row: 6 },\n]\n\nexport const WORLD_HEX_REGIONS: HexState[] = [\n  { id: 'CA', name: 'Canada', col: 2, row: 0 },\n  { id: 'GL', name: 'Greenland', col: 4, row: 0 },\n  { id: 'NO', name: 'Nordics', col: 6, row: 0 },\n  { id: 'US-W', name: 'US West', col: 1, row: 1 },\n  { id: 'US-E', name: 'US East', col: 2, row: 1 },\n  { id: 'UK', name: 'United Kingdom', col: 5, row: 1 },\n  { id: 'EU-W', name: 'Western Europe', col: 6, row: 1 },\n  { id: 'EU-E', name: 'Eastern Europe', col: 7, row: 1 },\n  { id: 'RU', name: 'Northern Eurasia', col: 8, row: 1 },\n  { id: 'MX', name: 'Mexico', col: 1, row: 2 },\n  { id: 'MED', name: 'Mediterranean', col: 6, row: 2 },\n  { id: 'ME', name: 'Middle East', col: 7, row: 2 },\n  { id: 'CN', name: 'East Asia', col: 8, row: 2 },\n  { id: 'JP', name: 'Japan', col: 9, row: 2 },\n  { id: 'BR', name: 'Brazil', col: 2, row: 3 },\n  { id: 'AF-N', name: 'North Africa', col: 5, row: 3 },\n  { id: 'IN', name: 'South Asia', col: 7, row: 3 },\n  { id: 'SEA', name: 'Southeast Asia', col: 8, row: 3 },\n  { id: 'AR', name: 'South Cone', col: 2, row: 4 },\n  { id: 'AF-S', name: 'Sub-Saharan', col: 5, row: 4 },\n  { id: 'AU', name: 'Australia & Oceania', col: 8, row: 4 },\n]\n\nconst US_CENTROIDS: Record<string, [number, number]> = {\n  AK: [-152.4, 64.2],\n  ME: [-69.4, 45.3],\n  WA: [-120.7, 47.7],\n  ID: [-114.7, 44.1],\n  MT: [-110.4, 46.9],\n  ND: [-100.5, 47.5],\n  MN: [-94.6, 46.7],\n  IL: [-89.4, 40.6],\n  WI: [-89.6, 43.8],\n  MI: [-85.6, 44.3],\n  NY: [-74.2, 43.3],\n  VT: [-72.6, 44.6],\n  NH: [-71.6, 43.2],\n  OR: [-120.5, 43.8],\n  NV: [-116.4, 38.8],\n  WY: [-107.3, 43.1],\n  SD: [-99.9, 44.3],\n  IA: [-93.5, 42.0],\n  IN: [-86.1, 40.3],\n  OH: [-82.9, 40.4],\n  PA: [-77.2, 41.2],\n  NJ: [-74.4, 40.1],\n  MA: [-71.4, 42.4],\n  RI: [-71.5, 41.6],\n  CA: [-119.4, 36.8],\n  UT: [-111.1, 39.3],\n  CO: [-105.8, 39.5],\n  NE: [-99.9, 41.5],\n  MO: [-91.8, 37.9],\n  KY: [-84.3, 37.8],\n  WV: [-80.4, 38.6],\n  VA: [-78.7, 37.4],\n  MD: [-76.6, 39.0],\n  DE: [-75.5, 39.0],\n  AZ: [-111.1, 34.0],\n  NM: [-106.0, 34.5],\n  KS: [-98.5, 38.5],\n  AR: [-92.3, 34.8],\n  TN: [-86.6, 35.5],\n  NC: [-79.0, 35.8],\n  SC: [-81.2, 33.8],\n  DC: [-77.0, 38.9],\n  CT: [-72.7, 41.6],\n  OK: [-97.5, 35.0],\n  LA: [-91.9, 30.9],\n  MS: [-89.7, 32.4],\n  AL: [-86.9, 32.3],\n  GA: [-83.6, 32.2],\n  HI: [-157.8, 21.3],\n  TX: [-99.9, 31.9],\n  FL: [-81.5, 27.6],\n}\n\nfunction getCoords(item: HexState): [number, number] {\n  if (US_CENTROIDS[item.id]) return US_CENTROIDS[item.id]\n  const lng = -120 + item.col * 14\n  const lat = 50 - item.row * 8\n  return [lng, lat]\n}\n\n/**\n * <uip-hexbin-map> — the registry HexbinMap (React `HexbinMap`) as a web\n * component. Same hex/square tiles, selection card, projection toggle and\n * ramp legend as React, rendered on the shipped <uip-map> (markers as its\n * light-DOM children — the web-component stand-in for React's JSX children).\n *\n * Properties (React props): `shape` ('hexagon' | 'square'; default\n * 'hexagon'), `preset` ('us-states' | 'world-regions'; default 'us-states'),\n * `items` (HexState[]; defaults to the preset), `data` (Record<id,\n * HexbinDatum>), `selected`, `show-labels` (default true; accepted like\n * React, unused), `show-values` (default false), `value-formatter` (property\n * only — a function), `color-ramp` (default green oklch ramp), `empty-color`\n * (default 'rgba(255, 255, 255, 0.08)'), `height` (default 480), `interactive`\n * (default true), `aria-label` (React `ariaLabel`). `access-token` forwards a\n * Mapbox token to the inner map (elements never read the environment).\n * React's `className` → host classes.\n *\n * Events: `selected-change` (detail: id | undefined — React's\n * `onSelectedChange`), `select` (detail: { id, name, datum } — React's\n * `onSelect`).\n */\nexport class UipHexbinMap extends LitElement {\n  // :host display can't be a utility class (the host has no template of its own).\n  static styles = [tailwind, css`:host { display: block; }`]\n\n  static properties = {\n    shape: {},\n    preset: {},\n    items: { type: Array },\n    data: { type: Object },\n    selected: {},\n    showLabels: { attribute: 'show-labels', converter: defaultTrue },\n    showValues: { attribute: 'show-values', type: Boolean },\n    valueFormatter: { attribute: false },\n    colorRamp: { attribute: 'color-ramp', type: Array },\n    emptyColor: { attribute: 'empty-color' },\n    height: {},\n    interactive: { converter: defaultTrue },\n    accessToken: { attribute: 'access-token' },\n    accessibleLabel: { attribute: 'aria-label' },\n    internalSelected: { state: true },\n    projection: { state: true },\n  }\n\n  shape: 'hexagon' | 'square' = 'hexagon'\n  preset: 'us-states' | 'world-regions' = 'us-states'\n  items?: HexState[]\n  data: Record<string, HexbinDatum> = {}\n  selected?: string\n  showLabels = true\n  showValues = false\n  valueFormatter: (value: number) => string = (v: number) => v.toLocaleString()\n  colorRamp = [\n    'oklch(0.92 0.05 162)',\n    'oklch(0.82 0.10 162)',\n    'oklch(0.72 0.14 162)',\n    'oklch(0.62 0.17 162)',\n    'oklch(0.50 0.18 162)',\n    'oklch(0.38 0.16 162)',\n  ]\n  emptyColor = 'rgba(255, 255, 255, 0.08)'\n  height: number | string = 480\n  interactive = true\n  accessToken?: string\n  accessibleLabel?: string\n  private internalSelected?: string\n  private projection: 'globe' | 'mercator' = 'mercator'\n\n  constructor() {\n    super()\n    new ThemeController(this)\n  }\n\n  connectedCallback() {\n    super.connectedCallback()\n    this.setAttribute('data-uipkge', '')\n    this.setAttribute('data-slot', 'hexbin-map')\n    if (this.internalSelected === undefined) this.internalSelected = this.selected\n    this.projection = this.preset === 'world-regions' ? 'globe' : 'mercator'\n  }\n\n  private get activeSelected() {\n    return this.selected !== undefined ? this.selected : this.internalSelected\n  }\n\n  private get activeItems() {\n    if (this.items && this.items.length > 0) return this.items\n    return this.preset === 'world-regions' ? WORLD_HEX_REGIONS : US_HEX_STATES\n  }\n\n  private get values() {\n    return Object.values(this.data ?? {})\n      .map((d) => d.value)\n      .filter((v) => typeof v === 'number')\n  }\n\n  private getColor(datum?: HexbinDatum): string {\n    if (!datum) return this.emptyColor\n    if (datum.color) return datum.color\n\n    const values = this.values\n    const minValue = values.length ? Math.min(...values) : 0\n    const maxValue = values.length ? Math.max(...values) : 100\n    const val = datum.value\n    const span = maxValue - minValue\n    const normalized = span > 0 ? (val - minValue) / span : 0.5\n    const idx = Math.min(this.colorRamp.length - 1, Math.floor(normalized * this.colorRamp.length))\n    return this.colorRamp[idx]\n  }\n\n  private handleSelect(item: HexState) {\n    if (!this.interactive) return\n    this.internalSelected = item.id\n    this.dispatchEvent(new CustomEvent('selected-change', { detail: item.id, bubbles: true, composed: true }))\n    this.dispatchEvent(\n      new CustomEvent('select', { detail: { id: item.id, name: item.name, datum: this.data[item.id] }, bubbles: true, composed: true }),\n    )\n  }\n\n  private clearSelection() {\n    this.internalSelected = undefined\n    this.dispatchEvent(new CustomEvent('selected-change', { detail: undefined, bubbles: true, composed: true }))\n  }\n\n  private toggleProjection() {\n    this.projection = this.projection === 'globe' ? 'mercator' : 'globe'\n  }\n\n  render() {\n    const activeItems = this.activeItems\n    const activeSelected = this.activeSelected\n    const activeStateItem = activeItems.find((it) => it.id === activeSelected)\n    const activeStateDatum = activeSelected ? this.data[activeSelected] : undefined\n    const values = this.values\n    const minValue = values.length ? Math.min(...values) : 0\n    const maxValue = values.length ? Math.max(...values) : 100\n    const mapCenter: [number, number] = this.preset === 'world-regions' ? [0, 20] : [-97, 39]\n    const mapZoom = this.preset === 'world-regions' ? 1.5 : 3.6\n    return html`<div\n      part=\"base\"\n      aria-label=${this.accessibleLabel ?? 'Hexbin map'}\n      style=${styleMap({ height: heightToStyle(this.height) })}\n      class=\"border-border bg-card group relative w-full overflow-hidden rounded-xl border shadow-xs\"\n    >\n      <uip-map\n        .accessToken=${this.accessToken}\n        variant=\"dark\"\n        .projection=${this.projection}\n        .center=${mapCenter}\n        .zoom=${mapZoom}\n        class=\"size-full\"\n      >\n        ${activeItems.map((item) => {\n          const coords = getCoords(item)\n          const isSelected = activeSelected === item.id\n          const color = this.getColor(this.data[item.id])\n          return html`<uip-map-marker\n            longitude=${coords[0]}\n            latitude=${coords[1]}\n            anchor=\"center\"\n            class=${cn(\n              'cursor-pointer transition-transform select-none',\n              isSelected ? 'z-30 scale-115' : 'z-20 hover:scale-105',\n            )}\n          >\n            <button\n              type=\"button\"\n              class=\"group/hex relative flex size-10 items-center justify-center font-mono\"\n              @click=${() => this.handleSelect(item)}\n            >\n              <div\n                class=\"absolute inset-0 flex items-center justify-center\"\n                style=${styleMap({\n                  clipPath: this.shape === 'hexagon' ? 'polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%)' : 'none',\n                  backgroundColor: color,\n                  border: isSelected ? '2px solid white' : '1px solid rgba(255,255,255,0.2)',\n                  boxShadow: isSelected ? `0 0 14px ${color}` : 'none',\n                })}\n              ></div>\n\n              <div class=\"relative z-10 flex flex-col items-center justify-center text-center\">\n                <span class=\"text-[10px] font-bold text-white drop-shadow-sm\">${item.id}</span>\n                ${this.showValues && this.data[item.id]\n                  ? html`<span class=\"text-[8px] font-semibold text-white/90\"\n                      >${Math.round(this.data[item.id].value)}</span\n                    >`\n                  : null}\n              </div>\n            </button>\n          </uip-map-marker>`\n        })}\n      </uip-map>\n\n      <div\n        class=\"border-border/70 bg-card/85 absolute top-3 right-3 z-10 flex items-center gap-1 rounded-lg border p-1 shadow-xs backdrop-blur-md\"\n      >\n        <button\n          type=\"button\"\n          class=\"text-muted-foreground hover:bg-muted hover:text-foreground flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium transition\"\n          @click=${this.toggleProjection}\n        >\n          ${icon(Globe, 'globe', 'size-3.5')}\n          <span class=\"capitalize\">${this.projection}</span>\n        </button>\n      </div>\n\n      ${activeStateItem\n        ? html`<div\n            class=\"border-border/80 bg-card/95 animate-in fade-in slide-in-from-bottom-2 absolute bottom-3 left-3 z-10 max-w-sm rounded-xl border p-3.5 shadow-lg backdrop-blur-md duration-150\"\n          >\n            <div class=\"flex items-start justify-between gap-3\">\n              <div>\n                <div class=\"flex items-center gap-2\">\n                  <span class=\"size-2 rounded-full\" style=${styleMap({ backgroundColor: this.getColor(activeStateDatum) })}></span>\n                  <span class=\"text-muted-foreground font-mono text-xs tracking-wider uppercase\">\n                    ${activeStateDatum?.status || 'Region'}\n                  </span>\n                </div>\n                <h4 class=\"text-foreground mt-0.5 text-sm font-semibold\">\n                  ${activeStateItem.name} (${activeStateItem.id})\n                </h4>\n              </div>\n              <button\n                type=\"button\"\n                class=\"text-muted-foreground hover:text-foreground text-xs\"\n                @click=${this.clearSelection}\n              >\n                ✕\n              </button>\n            </div>\n\n            ${activeStateDatum\n              ? html`<div class=\"border-border/60 mt-2.5 flex items-baseline justify-between border-t pt-2 font-mono text-xs\">\n                  <span class=\"text-muted-foreground\">Adoption Metric</span>\n                  <span class=\"text-foreground font-semibold\">${this.valueFormatter(activeStateDatum.value)}%</span>\n                </div>`\n              : null}\n            ${activeStateDatum?.description\n              ? html`<p class=\"text-muted-foreground mt-1.5 text-xs leading-relaxed\">${activeStateDatum.description}</p>`\n              : null}\n          </div>`\n        : null}\n      ${values.length > 0\n        ? html`<div\n            class=\"border-border/70 bg-card/85 absolute right-3 bottom-3 z-10 hidden items-center gap-2 rounded-lg border px-3 py-2 text-xs shadow-xs backdrop-blur-md sm:flex\"\n          >\n            <span class=\"text-muted-foreground font-mono text-[10px]\">${minValue}</span>\n            <div class=\"flex h-2.5 gap-0.5 overflow-hidden rounded-xs\">\n              ${this.colorRamp.map((c) => html`<div class=\"w-3\" style=${styleMap({ backgroundColor: c })}></div>`)}\n            </div>\n            <span class=\"text-foreground font-mono text-[10px] font-semibold\">${maxValue}</span>\n          </div>`\n        : null}\n    </div>`\n  }\n}\n\ncustomElements.get('uip-hexbin-map') || customElements.define('uip-hexbin-map', UipHexbinMap)\n\ndeclare global {\n  interface HTMLElementTagNameMap {\n    'uip-hexbin-map': UipHexbinMap\n  }\n}\n",
      "type": "registry:file",
      "target": "src/uip/components/charts/hexbin-map.ts"
    },
    {
      "path": "packages/elements-lit/src/components/charts/lib/chart-element.ts",
      "content": "import { LitElement, css, html, type PropertyDeclarations, type PropertyValues } from 'lit'\nimport { styleMap } from 'lit/directives/style-map.js'\nimport type { ECharts } from 'echarts/core'\nimport { tailwind } from '../../../lib/styles'\nimport { ThemeController } from '../../../lib/theme'\nimport { heightToStyle, resolveChartTheme, subscribeChartTheme, type ChartTheme } from './chart-theme'\n\n/**\n * Attribute converter for booleans whose React default is `true`\n * (`showLabels`, `autoresize`): Lit's `type: Boolean` can't be switched off\n * from markup, so `show-labels=\"false\"` turns it off and anything else\n * (including removing the attribute) means true.\n */\nexport const defaultTrue = {\n  fromAttribute: (v: string | null) => v !== 'false',\n  toAttribute: (v: boolean) => (v ? '' : 'false'),\n}\n\n/**\n * `yField=\"value\"` from markup, `yField=['north', 'south']` from markup as a\n * JSON array or from JS as a property.\n */\nexport const stringOrArray = {\n  fromAttribute: (v: string | null) => (v?.trim().startsWith('[') ? (JSON.parse(v) as string[]) : v),\n}\n\n/**\n * Shared base for every ECharts-backed element — the Lit stand-in for React's\n * `ChartFrame` + `EChart` + `useChartTheme()`:\n *\n *  - renders React's ChartFrame chrome (role=\"img\", tabindex, focus ring,\n *    `height`) with a full-size inner container for the canvas;\n *  - resolves the chart theme from the CSS tokens and re-resolves it (and\n *    re-sets the option) whenever <html> class/style/data-theme changes;\n *  - lazily `import()`s echarts in firstUpdated (SSR-safe: nothing runs on the\n *    server), resizes with a ResizeObserver and disposes on disconnect;\n *  - applies `buildOption()` with `{ notMerge: true, lazyUpdate: true }`,\n *    exactly like React's EChart.\n *\n * Subclasses implement `buildOption()` (React's `mergedOption` useMemo) and\n * set `chartSlot` (the host's data-slot). `instance` exposes the ECharts\n * instance (undefined until initialised) for getOption()/dispatchAction().\n */\nexport abstract class ChartElement extends LitElement {\n  // :host display can't be a utility class (the host has no template of its own).\n  static styles = [tailwind, css`:host { display: block; }`]\n\n  static properties: PropertyDeclarations = {\n    height: {},\n    // role=\"img\" lives on the inner frame, so the host's aria-label is forwarded.\n    accessibleLabel: { attribute: 'aria-label' },\n    chartTheme: { state: true },\n  }\n\n  height: number | string = 300\n  accessibleLabel?: string\n  protected chartTheme: ChartTheme = resolveChartTheme()\n  /** Resize with the container. Only RawChart exposes it as a property. */\n  protected autoresize = true\n\n  protected abstract readonly chartSlot: string\n  protected abstract buildOption(): any\n\n  private chart?: ECharts\n  private resizeObserver?: ResizeObserver\n  private unsubscribeTheme?: () => void\n\n  constructor() {\n    super()\n    new ThemeController(this)\n  }\n\n  /** The ECharts instance, once initialised in the browser. */\n  get instance(): ECharts | undefined {\n    return this.chart\n  }\n\n  connectedCallback() {\n    super.connectedCallback()\n    this.setAttribute('data-uipkge', '')\n    this.setAttribute('data-slot', this.chartSlot)\n    this.chartTheme = resolveChartTheme()\n    this.unsubscribeTheme = subscribeChartTheme(() => {\n      this.chartTheme = resolveChartTheme()\n    })\n    // Re-attached after a move: firstUpdated won't run again.\n    if (this.hasUpdated) void this.initChart()\n  }\n\n  disconnectedCallback() {\n    super.disconnectedCallback()\n    this.unsubscribeTheme?.()\n    this.resizeObserver?.disconnect()\n    this.resizeObserver = undefined\n    this.chart?.dispose()\n    this.chart = undefined\n  }\n\n  protected firstUpdated() {\n    void this.initChart()\n  }\n\n  protected updated(changed: PropertyValues) {\n    if (!this.chart) return\n    if (changed.has('autoresize')) this.observeResize()\n    this.chart.setOption(this.buildOption(), { notMerge: true, lazyUpdate: true })\n  }\n\n  private get container() {\n    return this.renderRoot.querySelector<HTMLDivElement>('[data-chart]')\n  }\n\n  private async initChart() {\n    const { echarts } = await import('./echarts')\n    const el = this.container\n    if (!this.isConnected || this.chart || !el) return\n    this.chart = echarts.init(el)\n    this.chart.setOption(this.buildOption(), { notMerge: true, lazyUpdate: true })\n    this.observeResize()\n  }\n\n  private observeResize() {\n    this.resizeObserver?.disconnect()\n    this.resizeObserver = undefined\n    const el = this.container\n    if (!this.autoresize || !el) return\n    this.resizeObserver = new ResizeObserver(() => this.chart?.resize())\n    this.resizeObserver.observe(el)\n  }\n\n  render() {\n    return html`<div\n      part=\"base\"\n      role=\"img\"\n      aria-label=${this.accessibleLabel || 'Chart'}\n      tabindex=\"0\"\n      style=${styleMap({ height: heightToStyle(this.height) })}\n      class=\"focus-visible:ring-ring w-full focus-visible:ring-2 focus-visible:outline-none\"\n    >\n      <div data-chart class=\"h-full w-full\"></div>\n    </div>`\n  }\n}\n",
      "type": "registry:file",
      "target": "src/uip/components/charts/lib/chart-element.ts"
    },
    {
      "path": "packages/elements-lit/src/components/charts/lib/chart-theme.ts",
      "content": "import { isServer } from 'lit'\n\n// Port of packages/registry-react/components/charts/useChartTheme.ts.\n//\n// The chart palette is driven by the design tokens (`--chart-1`..`--chart-5`,\n// `--muted-foreground`, `--border`, `--popover`, …). They are resolved with\n// getComputedStyle on <html> and re-resolved whenever <html> class / style /\n// data-theme changes, so a light/dark flip re-colours every chart. Instead of\n// React's useChartTheme() hook, elements call subscribeChartTheme().\n\nconst listeners = new Set<() => void>()\nlet observing = false\n\nfunction bump() {\n  listeners.forEach((l) => l())\n}\n\n/** Call `cb` whenever the page theme changes. Returns the unsubscribe fn. */\nexport function subscribeChartTheme(cb: () => void): () => void {\n  listeners.add(cb)\n  if (!observing && !isServer) {\n    observing = true\n    // Same as React: one bump on the first frame (tokens resolved after the\n    // stylesheet applies), then on every <html> class/style/data-theme change.\n    requestAnimationFrame(bump)\n    new MutationObserver(bump).observe(document.documentElement, {\n      attributes: true,\n      attributeFilter: ['class', 'style', 'data-theme'],\n    })\n  }\n  return () => listeners.delete(cb)\n}\n\n// ECharts' canvas renderer does not accept OKLCH in every browser. Assigning\n// one of our Tailwind tokens to `fillStyle` can silently leave the sentinel\n// colour in place, turning a whole chart black. Convert OKLCH ourselves and\n// let the canvas normalize older CSS colour formats.\nlet _hexCanvas: CanvasRenderingContext2D | null = null\n\nexport function toCanvasColor(cssColor: string): string {\n  const value = cssColor.trim()\n  const match = value.match(\n    /^oklch\\(\\s*([+-]?(?:\\d+\\.?\\d*|\\.\\d+))(%?)\\s+([+-]?(?:\\d+\\.?\\d*|\\.\\d+))\\s+([+-]?(?:\\d+\\.?\\d*|\\.\\d+))(?:deg)?(?:\\s*\\/\\s*([+-]?(?:\\d+\\.?\\d*|\\.\\d+))(%?))?\\s*\\)$/i,\n  )\n\n  if (match) {\n    const lightness = Number(match[1]) / (match[2] === '%' ? 100 : 1)\n    const chroma = Number(match[3])\n    const hue = (Number(match[4]) * Math.PI) / 180\n    const alpha = match[5] == null ? 1 : Number(match[5]) / (match[6] === '%' ? 100 : 1)\n    const a = chroma * Math.cos(hue)\n    const b = chroma * Math.sin(hue)\n\n    const l = Math.pow(lightness + 0.3963377774 * a + 0.2158037573 * b, 3)\n    const m = Math.pow(lightness - 0.1055613458 * a - 0.0638541728 * b, 3)\n    const s = Math.pow(lightness - 0.0894841775 * a - 1.291485548 * b, 3)\n    const linear = [\n      4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n      -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n      -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,\n    ]\n    const rgb = linear.map((channel) => {\n      const encoded = channel <= 0.0031308 ? 12.92 * channel : 1.055 * Math.pow(channel, 1 / 2.4) - 0.055\n      return Math.round(Math.min(1, Math.max(0, encoded)) * 255)\n    })\n\n    return alpha < 1 ? `rgba(${rgb.join(', ')}, ${alpha})` : `rgb(${rgb.join(', ')})`\n  }\n\n  if (isServer) return cssColor\n  if (!_hexCanvas) {\n    _hexCanvas = document.createElement('canvas').getContext('2d')\n  }\n  if (!_hexCanvas) return cssColor\n  _hexCanvas.fillStyle = '#010203'\n  _hexCanvas.fillStyle = value\n  const normalized = _hexCanvas.fillStyle as string\n  return normalized === '#010203' && value.toLowerCase() !== '#010203' ? value : normalized\n}\n\n// Convert any CSS color (hex, rgb, oklch, color()) + alpha 0..1 to a\n// canvas-safe rgba(r,g,b,a).\nexport function toRgba(cssColor: string, alpha: number): string {\n  const normalized = toCanvasColor(cssColor)\n  if (normalized.startsWith('#') && normalized.length === 7) {\n    const r = parseInt(normalized.slice(1, 3), 16)\n    const g = parseInt(normalized.slice(3, 5), 16)\n    const b = parseInt(normalized.slice(5, 7), 16)\n    return `rgba(${r},${g},${b},${alpha})`\n  }\n  if (normalized.startsWith('rgba(')) {\n    return normalized.replace(/,\\s*[\\d.]+\\s*\\)$/, `,${alpha})`)\n  }\n  if (normalized.startsWith('rgb(')) {\n    return normalized.replace(/^rgb\\(/, 'rgba(').replace(/\\)$/, `,${alpha})`)\n  }\n  return cssColor\n}\n\nexport function resolveVar(name: string, fallback: string): string {\n  if (isServer) return fallback\n  const v = getComputedStyle(document.documentElement).getPropertyValue(name).trim()\n  if (!v) return fallback\n  return toCanvasColor(v)\n}\n\n// SSR / pre-hydration fallback palette (same values as React).\nconst CHART_FALLBACK = ['#f59e0b', '#14b8a6', '#3b82f6', '#f97316', '#eab308']\n\n/** The resolved chart theme tokens. All values are canvas-safe hex/rgba. */\nexport interface ChartTheme {\n  colors: string[]\n  textColor: string\n  axisColor: string\n  splitLineColor: string\n  tooltipBg: string\n  tooltipBorder: string\n  tooltipText: string\n  bgColor: string\n  accentColor: string\n  dangerColor: string\n  /** `--card`: cell borders and inside-label text, so they read as gaps /\n   *  contrast on light and dark surfaces (never '#fff'). */\n  surfaceColor: string\n  /** `--foreground`: primary numbers drawn on the canvas (gauge value). */\n  foregroundColor: string\n  /** Gauge stoplight from the status tokens, same rule as <uip-usage-bar>:\n   *  < 70% success, 70-89% warning, >= 90% destructive. */\n  semanticGaugeThresholds: [number, string][]\n}\n\nexport function resolveChartTheme(): ChartTheme {\n  return {\n    colors: Array.from({ length: 5 }, (_, i) => resolveVar(`--chart-${i + 1}`, CHART_FALLBACK[i]!)),\n    textColor: resolveVar('--muted-foreground', '#888888'),\n    axisColor: resolveVar('--border', '#e5e5e5'),\n    splitLineColor: resolveVar('--border', '#f0f0f0'),\n    tooltipBg: resolveVar('--popover', 'rgba(255,255,255,0.96)'),\n    tooltipBorder: resolveVar('--border', '#e5e5e5'),\n    tooltipText: resolveVar('--popover-foreground', '#333333'),\n    bgColor: resolveVar('--card', resolveVar('--background', '#ffffff')),\n    accentColor: resolveVar('--primary', '#38bdf8'),\n    dangerColor: resolveVar('--destructive', '#dc2626'),\n    surfaceColor: resolveVar('--card', '#ffffff'),\n    foregroundColor: resolveVar('--foreground', '#171717'),\n    semanticGaugeThresholds: [\n      [0.7, resolveVar('--success', '#14b8a6')],\n      [0.9, resolveVar('--warning', '#f59e0b')],\n      [1, resolveVar('--destructive', '#dc2626')],\n    ],\n  }\n}\n\n// Two-level deep merge for ECharts option blocks (verbatim from React): top-level\n// keys merge shallowly, and one nested level (axisLabel, splitLine, …) merges\n// shallowly too. Arrays + primitives replace outright — including a whole\n// block given as an array (e.g. `xAxis: [a, b]` for two axes).\nexport function mergeOptionBlock<T extends Record<string, any>>(base: T, user: Partial<T> | undefined): T {\n  if (!user) return base\n  if (Array.isArray(user)) return user as unknown as T\n  const out: any = { ...base }\n  for (const k of Object.keys(user)) {\n    const bv = (base as any)[k]\n    const uv = (user as any)[k]\n    if (\n      bv != null &&\n      uv != null &&\n      typeof bv === 'object' &&\n      typeof uv === 'object' &&\n      !Array.isArray(bv) &&\n      !Array.isArray(uv)\n    ) {\n      out[k] = { ...bv, ...uv }\n    } else {\n      out[k] = uv\n    }\n  }\n  return out\n}\n\n/** `height` prop → CSS: bare digits are px, anything else is raw CSS. */\nexport function heightToStyle(height: number | string): string {\n  return /^\\d+$/.test(String(height)) ? `${height}px` : String(height)\n}\n",
      "type": "registry:file",
      "target": "src/uip/components/charts/lib/chart-theme.ts"
    },
    {
      "path": "packages/elements-lit/src/components/charts/lib/echarts.ts",
      "content": "// ECharts core with every chart type / component the React wrappers register\n// (same list as packages/registry-react/components/charts/shared.tsx), so\n// <uip-raw-chart> can render any of them. Only ever loaded with a dynamic\n// import() from ChartElement.firstUpdated — never at module scope — so the\n// elements stay SSR-safe and echarts stays out of the initial bundle.\n// (Lives in charts/lib/ so src/index.ts's components/*/*.ts glob skips it.)\nimport * as echarts from 'echarts/core'\nimport { CanvasRenderer } from 'echarts/renderers'\nimport {\n  LineChart,\n  BarChart,\n  PieChart,\n  ScatterChart,\n  EffectScatterChart,\n  PictorialBarChart,\n  RadarChart,\n  GaugeChart,\n  HeatmapChart,\n  TreemapChart,\n  FunnelChart,\n  BoxplotChart,\n  CandlestickChart,\n  CustomChart,\n  ChordChart,\n  MapChart,\n  GraphChart,\n  ParallelChart,\n  SankeyChart,\n  SunburstChart,\n  ThemeRiverChart,\n  TreeChart,\n} from 'echarts/charts'\nimport {\n  GridComponent,\n  PolarComponent,\n  TooltipComponent,\n  LegendComponent,\n  MarkLineComponent,\n  MarkAreaComponent,\n  MarkPointComponent,\n  GraphicComponent,\n  RadarComponent,\n  VisualMapComponent,\n  CalendarComponent,\n  DataZoomComponent,\n  ParallelComponent,\n  SingleAxisComponent,\n  TitleComponent,\n} from 'echarts/components'\n\necharts.use([\n  CanvasRenderer,\n  LineChart,\n  BarChart,\n  PieChart,\n  ScatterChart,\n  EffectScatterChart,\n  PictorialBarChart,\n  RadarChart,\n  GaugeChart,\n  HeatmapChart,\n  TreemapChart,\n  FunnelChart,\n  BoxplotChart,\n  CandlestickChart,\n  CustomChart,\n  ChordChart,\n  MapChart,\n  GraphChart,\n  ParallelChart,\n  SankeyChart,\n  SunburstChart,\n  ThemeRiverChart,\n  TreeChart,\n  GridComponent,\n  PolarComponent,\n  TooltipComponent,\n  LegendComponent,\n  MarkLineComponent,\n  MarkAreaComponent,\n  MarkPointComponent,\n  GraphicComponent,\n  RadarComponent,\n  VisualMapComponent,\n  CalendarComponent,\n  DataZoomComponent,\n  ParallelComponent,\n  SingleAxisComponent,\n  TitleComponent,\n])\n\nexport { echarts }\n",
      "type": "registry:file",
      "target": "src/uip/components/charts/lib/echarts.ts"
    }
  ],
  "dependencies": [
    "echarts",
    "lit",
    "lucide"
  ],
  "registryDependencies": [
    "https://uipkge.dev/r/lit/lit-core.json",
    "https://uipkge.dev/r/lit/map.json"
  ]
}
