{"spec_id":"qrcode-basic","library":"muix","language":"javascript","code":"// anyplot.ai\n// qrcode-basic: Basic QR Code Generator\n// Library: muix 9.17.0 | JavaScript 22.23.4\n// Quality: 88/100 | Updated: 2026-11-08\n//# anyplot-orientation: square\nimport { ChartsContainer } from \"@mui/x-charts/ChartsContainer\";\nimport { useDrawingArea } from \"@mui/x-charts/hooks\";\n\nconst t = window.ANYPLOT_TOKENS;\n\n// Constants\n// A QR symbol is black on white in both themes; only the page chrome flips\nconst MODULE_INK = \"#1A1A17\";\nconst SYMBOL_PAPER = \"#FAF8F1\";\nconst QUIET_ZONE = 4; // modules of blank border, the QR standard's minimum\nconst EC_RECOVERY = { L: 7, M: 15, Q: 25, H: 30 }; // percent of codewords each level can restore\nconst TITLE_H = 64;\nconst CAPTION_H = 56;\nconst OUTER_MARGIN = 40;\n\n// Data: replace these parameters with your own content and its encoded symbol\nconst CONTENT = \"https://anyplot.ai\"; // role: content\nconst ERROR_CORRECTION = \"M\"; // role: error_correction\n// The symbol a QR encoder writes for CONTENT at ERROR_CORRECTION (segno 1.6.6: version 2, byte mode,\n// mask 1), one string per module row, 1 = dark. The browser has no QR encoder, so new content needs\n// a new matrix from one, for example segno.make_qr(content, error=\"m\").matrix\n// The matrix is precomputed for CONTENT and ERROR_CORRECTION: changing CONTENT does not re-encode it.\nconst SYMBOL_ROWS = [\n  \"1111111010101010001111111\",\n  \"1000001000000000101000001\",\n  \"1011101011011101101011101\",\n  \"1011101001000000001011101\",\n  \"1011101001011110001011101\",\n  \"1000001010101000001000001\",\n  \"1111111010101010101111111\",\n  \"0000000001001001100000000\",\n  \"1010001100010110100100101\",\n  \"1001000011111101001101011\",\n  \"0111111100011001100011101\",\n  \"0010100101111100101001000\",\n  \"0111001101001101001100001\",\n  \"0101110010101001111100011\",\n  \"1110011010101111010001101\",\n  \"0011010001011011110111000\",\n  \"1100101100100110111110010\",\n  \"0000000010100110100010001\",\n  \"1111111011010000101010001\",\n  \"1000001000000101100010001\",\n  \"1011101000111101111110011\",\n  \"1011101000001000010010110\",\n  \"1011101011101110000111011\",\n  \"1000001001111010100110000\",\n  \"1111111011000110111001001\",\n];\n\n// Plot: reads only the parameters and the constants above\nconst size = SYMBOL_ROWS.length;\nconst darkModules = SYMBOL_ROWS.flatMap((row, r) => [...row].flatMap((cell, c) => (cell === \"1\" ? [{ r, c }] : [])));\nconst version = (size - 17) / 4;\n\nconst TITLE = \"qrcode-basic · javascript · muix · anyplot.ai\";\nconst CAPTION = `Encodes “${CONTENT}” · error correction ${ERROR_CORRECTION} (${EC_RECOVERY[ERROR_CORRECTION]} %) · version ${version}, ${size} × ${size} modules`;\n\n// Whole-pixel module size so every module edge is sharp; the quiet zone is part of the tile\nfunction SymbolModules() {\n  const { left, top, width } = useDrawingArea();\n  const cell = Math.floor(width / (size + 2 * QUIET_ZONE));\n  const tile = cell * (size + 2 * QUIET_ZONE);\n  const x0 = left + (width - tile) / 2;\n  const y0 = top + (width - tile) / 2;\n\n  return (\n    <g shapeRendering=\"crispEdges\">\n      <rect x={x0} y={y0} width={tile} height={tile} fill={SYMBOL_PAPER} />\n      {darkModules.map(({ r, c }) => (\n        <rect\n          key={`${r}-${c}`}\n          x={x0 + (QUIET_ZONE + c) * cell}\n          y={y0 + (QUIET_ZONE + r) * cell}\n          width={cell}\n          height={cell}\n          fill={MODULE_INK}\n        />\n      ))}\n    </g>\n  );\n}\n\nexport default function Chart() {\n  const { width, height } = window.ANYPLOT_SIZE;\n  const side = Math.min(width, height - TITLE_H - CAPTION_H) - OUTER_MARGIN * 2;\n\n  return (\n    <div style={{ width, height, display: \"flex\", flexDirection: \"column\", alignItems: \"center\" }}>\n      <div style={{ height: TITLE_H, display: \"flex\", alignItems: \"center\", fontSize: 22, fontWeight: 600, color: t.ink }}>\n        {TITLE}\n      </div>\n      <div style={{ flex: 1, display: \"flex\", alignItems: \"center\", justifyContent: \"center\" }}>\n        <ChartsContainer\n          width={side}\n          height={side}\n          series={[]}\n          xAxis={[{ position: \"none\" }]}\n          yAxis={[{ position: \"none\" }]}\n          margin={{ top: 0, right: 0, bottom: 0, left: 0 }}\n          skipAnimation\n        >\n          <SymbolModules />\n        </ChartsContainer>\n      </div>\n      <div style={{ height: CAPTION_H, display: \"flex\", alignItems: \"center\", fontSize: 16, color: t.inkSoft }}>\n        {CAPTION}\n      </div>\n    </div>\n  );\n}\n"}