{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "qr-generator",
  "type": "registry:component",
  "title": "QR Generator",
  "description": "A real QR code encoder with a generator panel: pick where the code will be printed and it appends a source parameter to your link so scans can be attributed, with a live preview, Download SVG and Copy link. Also exports QrCode and encodeQr.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "ordering",
    "qr code",
    "generator",
    "menu",
    "table",
    "svg",
    "tracking"
  ],
  "docs": "https://hyperblur.dev/effects/qr-generator",
  "files": [
    {
      "path": "registry/hyperblur/qr-generator.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/qr-generator.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type QrLevel = \"L\" | \"M\" | \"Q\" | \"H\";\n\nconst QR_LEVEL_INDEX: Record<QrLevel, number> = { L: 0, M: 1, Q: 2, H: 3 };\nconst QR_LEVEL_BITS: Record<QrLevel, number> = { L: 1, M: 0, Q: 3, H: 2 };\n\nconst QR_BLOCKS: number[][][] = [\n  [[7, 1, 19, 0, 0], [10, 1, 16, 0, 0], [13, 1, 13, 0, 0], [17, 1, 9, 0, 0]],\n  [[10, 1, 34, 0, 0], [16, 1, 28, 0, 0], [22, 1, 22, 0, 0], [28, 1, 16, 0, 0]],\n  [[15, 1, 55, 0, 0], [26, 1, 44, 0, 0], [18, 2, 17, 0, 0], [22, 2, 13, 0, 0]],\n  [[20, 1, 80, 0, 0], [18, 2, 32, 0, 0], [26, 2, 24, 0, 0], [16, 4, 9, 0, 0]],\n  [[26, 1, 108, 0, 0], [24, 2, 43, 0, 0], [18, 2, 15, 2, 16], [22, 2, 11, 2, 12]],\n  [[18, 2, 68, 0, 0], [16, 4, 27, 0, 0], [24, 4, 19, 0, 0], [28, 4, 15, 0, 0]],\n  [[20, 2, 78, 0, 0], [18, 4, 31, 0, 0], [18, 2, 14, 4, 15], [26, 4, 13, 1, 14]],\n  [[24, 2, 97, 0, 0], [22, 2, 38, 2, 39], [22, 4, 18, 2, 19], [26, 4, 14, 2, 15]],\n  [[30, 2, 116, 0, 0], [22, 3, 36, 2, 37], [20, 4, 16, 4, 17], [24, 4, 12, 4, 13]],\n  [[18, 2, 68, 2, 69], [26, 4, 43, 1, 44], [24, 6, 19, 2, 20], [28, 6, 15, 2, 16]],\n];\n\nconst QR_ALIGN: number[][] = [\n  [],\n  [6, 18],\n  [6, 22],\n  [6, 26],\n  [6, 30],\n  [6, 34],\n  [6, 22, 38],\n  [6, 24, 42],\n  [6, 26, 46],\n  [6, 28, 50],\n];\n\nconst QR_EXP = new Uint8Array(512);\nconst QR_LOG = new Uint8Array(256);\n{\n  let x = 1;\n  for (let i = 0; i < 255; i++) {\n    QR_EXP[i] = x;\n    QR_LOG[x] = i;\n    x <<= 1;\n    if (x & 0x100) x ^= 0x11d;\n  }\n  for (let i = 255; i < 512; i++) QR_EXP[i] = QR_EXP[i - 255];\n}\n\nfunction qrMul(a: number, b: number): number {\n  if (a === 0 || b === 0) return 0;\n  return QR_EXP[QR_LOG[a] + QR_LOG[b]];\n}\n\nfunction qrGenerator(degree: number): number[] {\n  let poly = [1];\n  for (let i = 0; i < degree; i++) {\n    const next = new Array<number>(poly.length + 1).fill(0);\n    for (let j = 0; j < poly.length; j++) {\n      next[j] ^= poly[j];\n      next[j + 1] ^= qrMul(poly[j], QR_EXP[i]);\n    }\n    poly = next;\n  }\n  return poly;\n}\n\nexport function qrReedSolomon(data: number[], degree: number): number[] {\n  const gen = qrGenerator(degree);\n  const rem = new Array<number>(degree).fill(0);\n  for (const byte of data) {\n    const factor = byte ^ rem[0];\n    rem.shift();\n    rem.push(0);\n    for (let i = 0; i < degree; i++) rem[i] ^= qrMul(gen[i + 1], factor);\n  }\n  return rem;\n}\n\nfunction qrUtf8(text: string): number[] {\n  return Array.from(new TextEncoder().encode(text));\n}\n\nfunction qrMaskBit(mask: number, x: number, y: number): boolean {\n  switch (mask) {\n    case 0: return (x + y) % 2 === 0;\n    case 1: return y % 2 === 0;\n    case 2: return x % 3 === 0;\n    case 3: return (x + y) % 3 === 0;\n    case 4: return (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;\n    case 5: return ((x * y) % 2) + ((x * y) % 3) === 0;\n    case 6: return (((x * y) % 2) + ((x * y) % 3)) % 2 === 0;\n    default: return (((x + y) % 2) + ((x * y) % 3)) % 2 === 0;\n  }\n}\n\nfunction qrFormatBits(level: QrLevel, mask: number): number {\n  const data = (QR_LEVEL_BITS[level] << 3) | mask;\n  let rem = data;\n  for (let i = 0; i < 10; i++) rem = (rem << 1) ^ ((rem >>> 9) * 0x537);\n  return ((data << 10) | rem) ^ 0x5412;\n}\n\nfunction qrVersionBits(version: number): number {\n  let rem = version;\n  for (let i = 0; i < 12; i++) rem = (rem << 1) ^ ((rem >>> 11) * 0x1f25);\n  return (version << 12) | rem;\n}\n\nfunction qrPenalty(m: boolean[][]): number {\n  const n = m.length;\n  let score = 0;\n  for (let pass = 0; pass < 2; pass++) {\n    for (let a = 0; a < n; a++) {\n      let run = 1;\n      for (let b = 1; b <= n; b++) {\n        const same = b < n && (pass === 0 ? m[a][b] === m[a][b - 1] : m[b][a] === m[b - 1][a]);\n        if (same) {\n          run++;\n        } else {\n          if (run >= 5) score += 3 + (run - 5);\n          run = 1;\n        }\n      }\n      for (let b = 0; b + 10 < n; b++) {\n        const at = (k: number) => (pass === 0 ? m[a][b + k] : m[b + k][a]);\n        const core = at(0) && !at(1) && at(2) && at(3) && at(4) && !at(5) && at(6);\n        const coreLate = at(4) && !at(5) && at(6) && at(7) && at(8) && !at(9) && at(10);\n        if (core && !at(7) && !at(8) && !at(9) && !at(10)) score += 40;\n        if (coreLate && !at(0) && !at(1) && !at(2) && !at(3)) score += 40;\n      }\n    }\n  }\n  let dark = 0;\n  for (let y = 0; y < n; y++) {\n    for (let x = 0; x < n; x++) {\n      if (m[y][x]) dark++;\n      if (y + 1 < n && x + 1 < n) {\n        const c = m[y][x];\n        if (c === m[y][x + 1] && c === m[y + 1][x] && c === m[y + 1][x + 1]) score += 3;\n      }\n    }\n  }\n  const percent = (dark * 100) / (n * n);\n  score += Math.floor(Math.abs(percent - 50) / 5) * 10;\n  return score;\n}\n\nexport function encodeQr(text: string, level: QrLevel = \"M\"): boolean[][] {\n  const bytes = qrUtf8(text);\n  const li = QR_LEVEL_INDEX[level];\n  let version = 0;\n  let dataCodewords = 0;\n  for (let v = 1; v <= 10; v++) {\n    const [, b1, d1, b2, d2] = QR_BLOCKS[v - 1][li];\n    const capacity = b1 * d1 + b2 * d2;\n    const countBits = v < 10 ? 8 : 16;\n    if (4 + countBits + bytes.length * 8 <= capacity * 8) {\n      version = v;\n      dataCodewords = capacity;\n      break;\n    }\n  }\n  if (version === 0) throw new RangeError(\"Text is too long for a version 10 QR code at this error correction level\");\n\n  const bits: number[] = [];\n  const put = (value: number, length: number) => {\n    for (let i = length - 1; i >= 0; i--) bits.push((value >>> i) & 1);\n  };\n  put(4, 4);\n  put(bytes.length, version < 10 ? 8 : 16);\n  for (const b of bytes) put(b, 8);\n  const limit = dataCodewords * 8;\n  put(0, Math.min(4, limit - bits.length));\n  while (bits.length % 8 !== 0) bits.push(0);\n  const data: number[] = [];\n  for (let i = 0; i < bits.length; i += 8) {\n    let byte = 0;\n    for (let j = 0; j < 8; j++) byte = (byte << 1) | bits[i + j];\n    data.push(byte);\n  }\n  for (let pad = 0xec; data.length < dataCodewords; pad ^= 0xec ^ 0x11) data.push(pad);\n\n  const [ecLen, b1, d1, b2, d2] = QR_BLOCKS[version - 1][li];\n  const blocks: number[][] = [];\n  const eccs: number[][] = [];\n  let offset = 0;\n  for (let i = 0; i < b1 + b2; i++) {\n    const len = i < b1 ? d1 : d2;\n    const block = data.slice(offset, offset + len);\n    offset += len;\n    blocks.push(block);\n    eccs.push(qrReedSolomon(block, ecLen));\n  }\n  const codewords: number[] = [];\n  const maxData = Math.max(d1, d2);\n  for (let i = 0; i < maxData; i++) for (const block of blocks) if (i < block.length) codewords.push(block[i]);\n  for (let i = 0; i < ecLen; i++) for (const ecc of eccs) codewords.push(ecc[i]);\n\n  const size = version * 4 + 17;\n  const modules: boolean[][] = Array.from({ length: size }, () => new Array<boolean>(size).fill(false));\n  const reserved: boolean[][] = Array.from({ length: size }, () => new Array<boolean>(size).fill(false));\n  const set = (x: number, y: number, dark: boolean) => {\n    modules[y][x] = dark;\n    reserved[y][x] = true;\n  };\n\n  for (let i = 0; i < size; i++) {\n    set(6, i, i % 2 === 0);\n    set(i, 6, i % 2 === 0);\n  }\n  const finder = (cx: number, cy: number) => {\n    for (let dy = -4; dy <= 4; dy++) {\n      for (let dx = -4; dx <= 4; dx++) {\n        const x = cx + dx;\n        const y = cy + dy;\n        if (x < 0 || y < 0 || x >= size || y >= size) continue;\n        const d = Math.max(Math.abs(dx), Math.abs(dy));\n        set(x, y, d !== 2 && d !== 4);\n      }\n    }\n  };\n  finder(3, 3);\n  finder(size - 4, 3);\n  finder(3, size - 4);\n  const align = QR_ALIGN[version - 1];\n  for (let i = 0; i < align.length; i++) {\n    for (let j = 0; j < align.length; j++) {\n      const last = align.length - 1;\n      if ((i === 0 && j === 0) || (i === 0 && j === last) || (i === last && j === 0)) continue;\n      for (let dy = -2; dy <= 2; dy++) {\n        for (let dx = -2; dx <= 2; dx++) {\n          set(align[i] + dx, align[j] + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1);\n        }\n      }\n    }\n  }\n\n  const drawFormat = (mask: number) => {\n    const f = qrFormatBits(level, mask);\n    const bit = (i: number) => ((f >>> i) & 1) === 1;\n    for (let i = 0; i <= 5; i++) set(8, i, bit(i));\n    set(8, 7, bit(6));\n    set(8, 8, bit(7));\n    set(7, 8, bit(8));\n    for (let i = 9; i < 15; i++) set(14 - i, 8, bit(i));\n    for (let i = 0; i < 8; i++) set(size - 1 - i, 8, bit(i));\n    for (let i = 8; i < 15; i++) set(8, size - 15 + i, bit(i));\n    set(8, size - 8, true);\n  };\n  drawFormat(0);\n\n  if (version >= 7) {\n    const v = qrVersionBits(version);\n    for (let i = 0; i < 18; i++) {\n      const dark = ((v >>> i) & 1) === 1;\n      const a = size - 11 + (i % 3);\n      const b = Math.floor(i / 3);\n      set(a, b, dark);\n      set(b, a, dark);\n    }\n  }\n\n  let bitIndex = 0;\n  for (let right = size - 1; right >= 1; right -= 2) {\n    if (right === 6) right = 5;\n    for (let vert = 0; vert < size; vert++) {\n      for (let j = 0; j < 2; j++) {\n        const x = right - j;\n        const upward = ((right + 1) & 2) === 0;\n        const y = upward ? size - 1 - vert : vert;\n        if (reserved[y][x]) continue;\n        if (bitIndex < codewords.length * 8) {\n          modules[y][x] = ((codewords[bitIndex >>> 3] >>> (7 - (bitIndex & 7))) & 1) === 1;\n          bitIndex++;\n        }\n      }\n    }\n  }\n\n  const applyMask = (mask: number) => {\n    for (let y = 0; y < size; y++) {\n      for (let x = 0; x < size; x++) {\n        if (!reserved[y][x] && qrMaskBit(mask, x, y)) modules[y][x] = !modules[y][x];\n      }\n    }\n  };\n\n  let best = 0;\n  let bestScore = Infinity;\n  for (let mask = 0; mask < 8; mask++) {\n    applyMask(mask);\n    drawFormat(mask);\n    const score = qrPenalty(modules);\n    if (score < bestScore) {\n      bestScore = score;\n      best = mask;\n    }\n    applyMask(mask);\n  }\n  applyMask(best);\n  drawFormat(best);\n  return modules;\n}\n\nexport interface QrCodeProps extends Omit<React.SVGAttributes<SVGSVGElement>, \"children\"> {\n  value?: string;\n  size?: number;\n  level?: QrLevel;\n  fg?: string;\n  bg?: string;\n  margin?: number;\n  rounded?: boolean;\n  logo?: React.ReactNode;\n  logoSize?: number;\n  title?: string;\n}\n\nexport const QrCode = React.forwardRef<SVGSVGElement, QrCodeProps>(function QrCode(\n  {\n    value = \"https://cornerkitchen.example/menu\",\n    size = 200,\n    level = \"M\",\n    fg = \"#0a0a0a\",\n    bg = \"#ffffff\",\n    margin = 2,\n    rounded = false,\n    logo,\n    logoSize = 0.22,\n    title,\n    className = \"\",\n    ...rest\n  },\n  ref,\n) {\n  const matrix = React.useMemo(() => {\n    try {\n      return encodeQr(value, logo ? (level === \"L\" || level === \"M\" ? \"Q\" : level) : level);\n    } catch {\n      return null;\n    }\n  }, [value, level, logo]);\n\n  if (!matrix) {\n    return (\n      <svg ref={ref} viewBox=\"0 0 10 10\" width={size} height={size} className={className} role=\"img\" aria-label=\"Text too long for a QR code\" {...rest}>\n        <rect width=\"10\" height=\"10\" fill={bg} />\n        <path d=\"M3 3l4 4M7 3l-4 4\" stroke={fg} strokeWidth=\"0.6\" strokeLinecap=\"round\" />\n      </svg>\n    );\n  }\n\n  const n = matrix.length;\n  const total = n + margin * 2;\n  const cut = logo ? Math.ceil(n * Math.min(0.3, Math.max(0.1, logoSize))) | 1 : 0;\n  const cutStart = (n - cut) / 2;\n  const inCut = (x: number, y: number) => cut > 0 && x >= cutStart && x < cutStart + cut && y >= cutStart && y < cutStart + cut;\n  const inEye = (x: number, y: number) => (x < 7 && y < 7) || (x >= n - 7 && y < 7) || (x < 7 && y >= n - 7);\n\n  let path = \"\";\n  const dots: React.ReactNode[] = [];\n  for (let y = 0; y < n; y++) {\n    for (let x = 0; x < n; x++) {\n      if (!matrix[y][x] || inCut(x, y)) continue;\n      if (rounded && inEye(x, y)) continue;\n      if (rounded) {\n        dots.push(<rect key={`${x}-${y}`} x={x + margin + 0.06} y={y + margin + 0.06} width=\"0.88\" height=\"0.88\" rx=\"0.36\" />);\n      } else {\n        path += `M${x + margin} ${y + margin}h1v1h-1z`;\n      }\n    }\n  }\n\n  const eyes = rounded\n    ? [\n        [margin, margin],\n        [margin + n - 7, margin],\n        [margin, margin + n - 7],\n      ].map(([ex, ey], i) => (\n        <g key={i}>\n          <path\n            fillRule=\"evenodd\"\n            d={`M${ex + 2} ${ey}h3a2 2 0 0 1 2 2v3a2 2 0 0 1 -2 2h-3a2 2 0 0 1 -2 -2v-3a2 2 0 0 1 2 -2z M${ex + 2} ${ey + 1}a1 1 0 0 0 -1 1v3a1 1 0 0 0 1 1h3a1 1 0 0 0 1 -1v-3a1 1 0 0 0 -1 -1z`}\n          />\n          <rect x={ex + 2} y={ey + 2} width=\"3\" height=\"3\" rx=\"0.9\" />\n        </g>\n      ))\n    : null;\n\n  return (\n    <svg\n      ref={ref}\n      xmlns=\"http://www.w3.org/2000/svg\"\n      viewBox={`0 0 ${total} ${total}`}\n      width={size}\n      height={size}\n      className={className}\n      role=\"img\"\n      aria-label={title ?? `QR code for ${value}`}\n      shapeRendering={rounded ? undefined : \"crispEdges\"}\n      {...rest}\n    >\n      <rect width={total} height={total} fill={bg} rx={rounded ? 1.2 : 0} />\n      <g fill={fg}>\n        {path ? <path d={path} /> : null}\n        {dots}\n        {eyes}\n      </g>\n      {logo ? (\n        <foreignObject x={cutStart + margin} y={cutStart + margin} width={cut} height={cut}>\n          <div style={{ width: \"100%\", height: \"100%\", display: \"flex\", alignItems: \"center\", justifyContent: \"center\" }}>{logo}</div>\n        </foreignObject>\n      ) : null}\n    </svg>\n  );\n});\n\nexport interface QrPlacement {\n  id: string;\n  label: string;\n  source: string;\n  numbered?: boolean;\n}\n\nexport interface QrGeneratorLabels {\n  heading: string;\n  placement: string;\n  tableNumber: string;\n  link: string;\n  download: string;\n  copy: string;\n  copied: string;\n  caption: string;\n  tableCaption: string;\n}\n\nexport interface QrGeneratorProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n  baseUrl?: string;\n  placements?: QrPlacement[];\n  value?: string;\n  defaultValue?: string;\n  onChange?: (placementId: string) => void;\n  tableNumber?: number;\n  defaultTableNumber?: number;\n  onTableNumberChange?: (n: number) => void;\n  sourceParam?: string;\n  level?: QrLevel;\n  fg?: string;\n  bg?: string;\n  margin?: number;\n  rounded?: boolean;\n  logo?: React.ReactNode;\n  fileName?: string;\n  accent?: string;\n  appearance?: \"dark\" | \"light\";\n  labels?: Partial<QrGeneratorLabels>;\n  onUrlChange?: (url: string) => void;\n}\n\nconst defaultPlacements: QrPlacement[] = [\n  { id: \"table\", label: \"Table\", source: \"table\", numbered: true },\n  { id: \"bio\", label: \"Bio link\", source: \"bio\" },\n  { id: \"bag\", label: \"Delivery bag\", source: \"bag\" },\n  { id: \"flyer\", label: \"Flyer\", source: \"flyer\" },\n];\n\nconst defaultLabels: QrGeneratorLabels = {\n  heading: \"Menu QR code\",\n  placement: \"Where will it be scanned?\",\n  tableNumber: \"Table\",\n  link: \"Tracked link\",\n  download: \"Download SVG\",\n  copy: \"Copy link\",\n  copied: \"Copied\",\n  caption: \"Scan to see the menu\",\n  tableCaption: \"Table {n} · scan to order\",\n};\n\nexport function withSource(baseUrl: string, param: string, source: string): string {\n  const hashAt = baseUrl.indexOf(\"#\");\n  const hash = hashAt >= 0 ? baseUrl.slice(hashAt) : \"\";\n  const head = hashAt >= 0 ? baseUrl.slice(0, hashAt) : baseUrl;\n  const qAt = head.indexOf(\"?\");\n  const path = qAt >= 0 ? head.slice(0, qAt) : head;\n  const query = qAt >= 0 ? head.slice(qAt + 1) : \"\";\n  const kept = query.split(\"&\").filter((part) => part !== \"\" && part.split(\"=\")[0] !== param);\n  kept.push(`${encodeURIComponent(param)}=${encodeURIComponent(source)}`);\n  return `${path}?${kept.join(\"&\")}${hash}`;\n}\n\nfunction PlacementIcon({ id }: { id: string }) {\n  const common = { width: 15, height: 15, viewBox: \"0 0 24 24\", fill: \"none\", stroke: \"currentColor\", strokeWidth: 1.8, strokeLinecap: \"round\" as const, strokeLinejoin: \"round\" as const, \"aria-hidden\": true };\n  if (id === \"table\") {\n    return (\n      <svg {...common}>\n        <path d=\"M3 9h18M5 9v10M19 9v10M8 9l1-4h6l1 4\" />\n      </svg>\n    );\n  }\n  if (id === \"bio\") {\n    return (\n      <svg {...common}>\n        <path d=\"M10 14a4 4 0 0 0 5.66 0l3-3a4 4 0 0 0-5.66-5.66l-1 1\" />\n        <path d=\"M14 10a4 4 0 0 0-5.66 0l-3 3a4 4 0 0 0 5.66 5.66l1-1\" />\n      </svg>\n    );\n  }\n  if (id === \"bag\") {\n    return (\n      <svg {...common}>\n        <path d=\"M5 8h14l-1 12H6L5 8z\" />\n        <path d=\"M9 8V6a3 3 0 0 1 6 0v2\" />\n      </svg>\n    );\n  }\n  return (\n    <svg {...common}>\n      <path d=\"M6 3h9l3 3v15H6z\" />\n      <path d=\"M9 11h6M9 15h6M9 7h3\" />\n    </svg>\n  );\n}\n\nconst css = `\n.hb-od3 {\n  --hb-od3-accent: #2f7bff;\n  --hb-od3-bg: #111111;\n  --hb-od3-surface: #171717;\n  --hb-od3-line: #262626;\n  --hb-od3-text: #ededed;\n  --hb-od3-muted: #8f8f8f;\n  --hb-od3-chip: rgba(255, 255, 255, 0.04);\n  box-sizing: border-box;\n  container-type: inline-size;\n  width: 100%;\n  color: var(--hb-od3-text);\n  font-family: inherit;\n  font-size: 12px;\n  line-height: 1.4;\n}\n.hb-od3[data-appearance=\"light\"] {\n  --hb-od3-bg: #ffffff;\n  --hb-od3-surface: #f6f6f4;\n  --hb-od3-line: #e4e4e0;\n  --hb-od3-text: #141414;\n  --hb-od3-muted: #6b6b6b;\n  --hb-od3-chip: rgba(0, 0, 0, 0.03);\n}\n.hb-od3 *, .hb-od3 *::before, .hb-od3 *::after { box-sizing: border-box; }\n.hb-od3-card {\n  display: grid;\n  grid-template-columns: 1fr;\n  gap: 14px;\n  padding: 14px;\n  border: 1px solid var(--hb-od3-line);\n  border-radius: 18px;\n  background: var(--hb-od3-bg);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);\n}\n.hb-od3-preview {\n  position: relative;\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  gap: 8px;\n  padding: 12px;\n  border-radius: 14px;\n  background:\n    radial-gradient(120% 80% at 50% 0%, color-mix(in srgb, var(--hb-od3-accent) 22%, transparent), transparent 70%),\n    var(--hb-od3-surface);\n  border: 1px solid var(--hb-od3-line);\n}\n.hb-od3-frame {\n  position: relative;\n  width: min(100%, 180px);\n  padding: 8px;\n  border-radius: 12px;\n  background: #ffffff;\n  box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(0, 0, 0, 0.06);\n  animation: hb-od3-pop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;\n}\n.hb-od3-frame svg { display: block; width: 100%; height: auto; }\n.hb-od3-caption {\n  color: var(--hb-od3-muted);\n  font-size: 11px;\n  text-align: center;\n  white-space: nowrap;\n  overflow: hidden;\n  text-overflow: ellipsis;\n  max-width: 100%;\n}\n.hb-od3-side {\n  display: flex;\n  min-width: 0;\n  flex-direction: column;\n  gap: 10px;\n}\n.hb-od3-head {\n  display: flex;\n  align-items: baseline;\n  justify-content: space-between;\n  gap: 8px;\n}\n.hb-od3-title { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: -0.01em; }\n.hb-od3-level {\n  color: var(--hb-od3-muted);\n  font-size: 10px;\n  font-variant-numeric: tabular-nums;\n  white-space: nowrap;\n}\n.hb-od3-label {\n  display: block;\n  margin: 0 0 6px;\n  color: var(--hb-od3-muted);\n  font-size: 11px;\n}\n.hb-od3-places {\n  display: grid;\n  grid-template-columns: repeat(2, minmax(0, 1fr));\n  gap: 6px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n}\n.hb-od3-place {\n  display: flex;\n  min-width: 0;\n  align-items: center;\n  gap: 6px;\n  height: 30px;\n  padding: 0 9px;\n  border: 1px solid var(--hb-od3-line);\n  border-radius: 9px;\n  background: var(--hb-od3-chip);\n  color: var(--hb-od3-muted);\n  font: inherit;\n  font-size: 11.5px;\n  cursor: pointer;\n  transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease;\n}\n.hb-od3-place span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-od3-place svg { flex: none; }\n.hb-od3-place:hover { color: var(--hb-od3-text); border-color: color-mix(in srgb, var(--hb-od3-text) 22%, transparent); }\n.hb-od3-place[aria-checked=\"true\"] {\n  color: var(--hb-od3-text);\n  border-color: var(--hb-od3-accent);\n  background: color-mix(in srgb, var(--hb-od3-accent) 14%, transparent);\n}\n.hb-od3-place:focus-visible, .hb-od3-btn:focus-visible, .hb-od3-num:focus-visible {\n  outline: 2px solid var(--hb-od3-accent);\n  outline-offset: 2px;\n}\n.hb-od3-row {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  min-width: 0;\n}\n.hb-od3-numwrap {\n  display: flex;\n  flex: none;\n  align-items: center;\n  gap: 6px;\n  color: var(--hb-od3-muted);\n  font-size: 11px;\n}\n.hb-od3-num {\n  width: 52px;\n  height: 28px;\n  padding: 0 8px;\n  border: 1px solid var(--hb-od3-line);\n  border-radius: 8px;\n  background: var(--hb-od3-surface);\n  color: var(--hb-od3-text);\n  font: inherit;\n  font-size: 12px;\n  font-variant-numeric: tabular-nums;\n}\n.hb-od3-url {\n  flex: 1;\n  min-width: 0;\n  height: 28px;\n  padding: 0 9px;\n  border: 1px dashed var(--hb-od3-line);\n  border-radius: 8px;\n  color: var(--hb-od3-muted);\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: 10.5px;\n  line-height: 26px;\n  white-space: nowrap;\n  overflow: hidden;\n  text-overflow: ellipsis;\n}\n.hb-od3-url { display: flex; }\n.hb-od3-urlhead { min-width: 0; overflow: hidden; text-overflow: ellipsis; }\n.hb-od3-url b { flex: none; color: var(--hb-od3-accent); font-weight: 500; }\n.hb-od3-actions {\n  display: grid;\n  grid-template-columns: repeat(2, minmax(0, 1fr));\n  gap: 6px;\n}\n.hb-od3-btn {\n  display: inline-flex;\n  min-width: 0;\n  align-items: center;\n  justify-content: center;\n  gap: 6px;\n  height: 30px;\n  padding: 0 10px;\n  border: 1px solid var(--hb-od3-line);\n  border-radius: 999px;\n  background: transparent;\n  color: var(--hb-od3-text);\n  font: inherit;\n  font-size: 11.5px;\n  font-weight: 500;\n  white-space: nowrap;\n  cursor: pointer;\n  transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease;\n}\n.hb-od3-btn:hover { border-color: color-mix(in srgb, var(--hb-od3-text) 30%, transparent); }\n.hb-od3-btn:active { transform: scale(0.97); }\n.hb-od3-btn[data-primary=\"true\"] {\n  border-color: transparent;\n  background: var(--hb-od3-text);\n  color: var(--hb-od3-bg);\n}\n.hb-od3-btn[data-primary=\"true\"]:hover { background: color-mix(in srgb, var(--hb-od3-text) 86%, transparent); }\n.hb-od3-btn[data-done=\"true\"] { border-color: #22c55e; color: #22c55e; }\n.hb-od3-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n}\n@container (min-width: 300px) {\n  .hb-od3-card { grid-template-columns: 38% minmax(0, 1fr); align-items: stretch; }\n  .hb-od3-head .hb-od3-level { display: none; }\n}\n@container (min-width: 300px) and (max-width: 420px) {\n  .hb-od3-card { gap: 12px; padding: 12px; }\n  .hb-od3-preview { padding: 8px; gap: 6px; }\n  .hb-od3-side { gap: 8px; }\n  .hb-od3-label { display: none; }\n  .hb-od3-place { height: 26px; padding: 0 7px; font-size: 11px; }\n  .hb-od3-btn { height: 28px; font-size: 11px; padding: 0 6px; }\n  .hb-od3-num, .hb-od3-url { height: 26px; }\n  .hb-od3-url { line-height: 24px; }\n  .hb-od3-btn svg { display: none; }\n}\n@container (min-width: 560px) {\n  .hb-od3-card { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 20px; padding: 20px; }\n  .hb-od3-preview { padding: 22px; }\n  .hb-od3-frame { width: min(100%, 220px); }\n  .hb-od3-title { font-size: 15px; }\n  .hb-od3-head .hb-od3-level { display: inline; }\n  .hb-od3-places { grid-template-columns: repeat(2, minmax(0, 1fr)); }\n  .hb-od3-place { height: 36px; }\n  .hb-od3-btn { height: 36px; }\n}\n@keyframes hb-od3-pop {\n  from { opacity: 0; transform: scale(0.94); }\n  to { opacity: 1; transform: scale(1); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-od3-frame { animation: none; }\n  .hb-od3-place, .hb-od3-btn { transition: none; }\n}\n`;\n\nexport function QrGenerator({\n  baseUrl = \"https://cornerkitchen.example/menu\",\n  placements = defaultPlacements,\n  value,\n  defaultValue,\n  onChange,\n  tableNumber,\n  defaultTableNumber = 5,\n  onTableNumberChange,\n  sourceParam = \"src\",\n  level = \"M\",\n  fg = \"#0a0a0a\",\n  bg = \"#ffffff\",\n  margin = 1,\n  rounded = true,\n  logo,\n  fileName = \"menu-qr\",\n  accent = \"#2f7bff\",\n  appearance = \"dark\",\n  labels,\n  onUrlChange,\n  className = \"\",\n  style,\n  ...rest\n}: QrGeneratorProps) {\n  const l = { ...defaultLabels, ...labels };\n  const [inner, setInner] = React.useState(defaultValue ?? placements[0]?.id ?? \"\");\n  const [innerTable, setInnerTable] = React.useState(defaultTableNumber);\n  const [copied, setCopied] = React.useState(false);\n  const svgRef = React.useRef<SVGSVGElement>(null);\n  const timer = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n  const idBase = React.useId();\n\n  const active = value ?? inner;\n  const table = tableNumber ?? innerTable;\n  const placement = placements.find((p) => p.id === active) ?? placements[0];\n  const source = placement ? (placement.numbered ? `${placement.source}-${table}` : placement.source) : \"\";\n  const url = source ? withSource(baseUrl, sourceParam, source) : baseUrl;\n  const caption = placement?.numbered ? l.tableCaption.replace(\"{n}\", String(table)) : l.caption;\n\n  React.useEffect(() => {\n    onUrlChange?.(url);\n  }, [url, onUrlChange]);\n\n  React.useEffect(() => () => {\n    if (timer.current) clearTimeout(timer.current);\n  }, []);\n\n  const choose = (id: string) => {\n    if (value === undefined) setInner(id);\n    onChange?.(id);\n  };\n\n  const onKey = (e: React.KeyboardEvent<HTMLButtonElement>, index: number) => {\n    const keys: Record<string, number> = { ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 };\n    if (!(e.key in keys) && e.key !== \"Home\" && e.key !== \"End\") return;\n    e.preventDefault();\n    let next = index + (keys[e.key] ?? 0);\n    if (e.key === \"Home\") next = 0;\n    if (e.key === \"End\") next = placements.length - 1;\n    next = (next + placements.length) % placements.length;\n    choose(placements[next].id);\n    const group = e.currentTarget.parentElement;\n    const target = group?.querySelectorAll<HTMLButtonElement>(\"button\")[next];\n    target?.focus();\n  };\n\n  const changeTable = (raw: string) => {\n    const n = Math.max(1, Math.min(999, Math.floor(Number(raw) || 1)));\n    if (tableNumber === undefined) setInnerTable(n);\n    onTableNumberChange?.(n);\n  };\n\n  const download = () => {\n    const node = svgRef.current;\n    if (!node) return;\n    const markup = new XMLSerializer().serializeToString(node);\n    const blob = new Blob([`<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n${markup}`], { type: \"image/svg+xml\" });\n    const href = URL.createObjectURL(blob);\n    const a = document.createElement(\"a\");\n    a.href = href;\n    a.download = `${fileName}-${source || \"link\"}.svg`;\n    document.body.appendChild(a);\n    a.click();\n    a.remove();\n    setTimeout(() => URL.revokeObjectURL(href), 1000);\n  };\n\n  const copy = async () => {\n    try {\n      await navigator.clipboard.writeText(url);\n    } catch {\n      const area = document.createElement(\"textarea\");\n      area.value = url;\n      area.setAttribute(\"readonly\", \"\");\n      area.style.position = \"fixed\";\n      area.style.opacity = \"0\";\n      document.body.appendChild(area);\n      area.select();\n      const ok = (() => {\n        try {\n          return document.execCommand(\"copy\");\n        } catch {\n          return false;\n        }\n      })();\n      area.remove();\n      if (!ok) return;\n    }\n    setCopied(true);\n    if (timer.current) clearTimeout(timer.current);\n    timer.current = setTimeout(() => setCopied(false), 1600);\n  };\n\n  const qIndex = url.indexOf(`${sourceParam}=`);\n  const urlHead = qIndex >= 0 ? url.slice(0, qIndex) : url;\n  const urlTail = qIndex >= 0 ? url.slice(qIndex) : \"\";\n\n  return (\n    <div\n      className={`hb-od3 ${className}`}\n      data-appearance={appearance}\n      style={{ \"--hb-od3-accent\": accent, ...style } as React.CSSProperties}\n      {...rest}\n    >\n      <style href=\"hb-qr-generator\" precedence=\"default\">{css}</style>\n      <div className=\"hb-od3-card\">\n        <div className=\"hb-od3-preview\">\n          <div className=\"hb-od3-frame\" key={url}>\n            <QrCode ref={svgRef} value={url} level={level} fg={fg} bg={bg} margin={margin} rounded={rounded} logo={logo} size={180} title={`QR code for ${url}`} />\n          </div>\n          <span className=\"hb-od3-caption\">{caption}</span>\n        </div>\n        <div className=\"hb-od3-side\">\n          <div className=\"hb-od3-head\">\n            <h3 className=\"hb-od3-title\">{l.heading}</h3>\n            <span className=\"hb-od3-level\">{`Level ${level}`}</span>\n          </div>\n          <div>\n            <span className=\"hb-od3-label\" id={`${idBase}-pl`}>{l.placement}</span>\n            <div className=\"hb-od3-places\" role=\"radiogroup\" aria-labelledby={`${idBase}-pl`}>\n              {placements.map((p, i) => (\n                <button\n                  key={p.id}\n                  type=\"button\"\n                  role=\"radio\"\n                  aria-checked={p.id === placement?.id}\n                  tabIndex={p.id === placement?.id ? 0 : -1}\n                  className=\"hb-od3-place\"\n                  onClick={() => choose(p.id)}\n                  onKeyDown={(e) => onKey(e, i)}\n                >\n                  <PlacementIcon id={p.id} />\n                  <span>{p.label}</span>\n                </button>\n              ))}\n            </div>\n          </div>\n          <div className=\"hb-od3-row\">\n            {placement?.numbered ? (\n              <label className=\"hb-od3-numwrap\">\n                {l.tableNumber}\n                <input\n                  className=\"hb-od3-num\"\n                  type=\"number\"\n                  inputMode=\"numeric\"\n                  min={1}\n                  max={999}\n                  value={table}\n                  onChange={(e) => changeTable(e.target.value)}\n                />\n              </label>\n            ) : null}\n            <span className=\"hb-od3-url\" title={url}>\n              <span className=\"hb-od3-sr\">{`${l.link}: `}</span>\n              <span className=\"hb-od3-urlhead\">{urlHead.replace(/^https?:[/][/]/, \"\")}</span>\n              <b>{urlTail}</b>\n            </span>\n          </div>\n          <div className=\"hb-od3-actions\">\n            <button type=\"button\" className=\"hb-od3-btn\" data-primary=\"true\" onClick={download}>\n              <svg width=\"13\" height=\"13\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <path d=\"M12 4v11M7 10l5 5 5-5M5 20h14\" />\n              </svg>\n              {l.download}\n            </button>\n            <button type=\"button\" className=\"hb-od3-btn\" data-done={copied} onClick={copy} aria-live=\"polite\">\n              <svg width=\"13\" height=\"13\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                {copied ? <path d=\"M5 12l5 5L20 7\" /> : <path d=\"M9 9h10v10H9zM5 15V5h10\" />}\n              </svg>\n              {copied ? l.copied : l.copy}\n            </button>\n          </div>\n        </div>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}