# Qrcode
An in-house pure-JS QR code encoder (@lh-ui/share/core/qrcode, full ISO/IEC 18004 chain: UTF-8 byte mode → Reed-Solomon error correction → mask penalty selection → format / version info BCH). The matrix is rendered as an SVG <path>; the viewBox includes the quiet zone. Root class lh-qrcode, styles come from share styles/qrcode.
<template>
<div class="demo-col" style="gap: 18px; max-width: 480px">
<div class="demo-row" style="gap: 12px; flex-wrap: wrap; align-items: center">
<LhInput v-model="text" placeholder="Text to encode" style="width: 220px" />
<LhButton size="small" @click="cycleLevel">Error level: {{ level }}</LhButton>
</div>
<div class="demo-row" style="gap: 24px; flex-wrap: wrap; align-items: flex-start">
<div class="demo-col" style="align-items: center; gap: 8px">
<LhQrcode :value="text" :level="level" label="Default QR code" />
<span class="demo-note">Default (level M / size=120)</span>
</div>
<div class="demo-col" style="align-items: center; gap: 8px">
<LhQrcode :value="text" :level="level" :size="160" :margin="2" color="#A63D40" />
<span class="demo-note">size=160 margin=2 cinnabar modules</span>
</div>
<div class="demo-col" style="align-items: center; gap: 8px">
<LhQrcode :value="text" :level="level" :version="5" bg-color="#F6F1EA" />
<span class="demo-note">version=5 fixed + background rect</span>
</div>
</div>
<div class="demo-row" style="gap: 24px; flex-wrap: wrap; align-items: flex-start">
<div class="demo-col" style="align-items: center; gap: 8px">
<LhQrcode value="" />
<span class="demo-note">Empty value, empty state</span>
</div>
<div class="demo-col" style="align-items: center; gap: 8px">
<LhQrcode :value="tooLong" />
<span class="demo-note">Over-capacity text falls back to the empty state (console.warn)</span>
</div>
</div>
</div>
</template>
<script>
export default {
data: () => ({
text: 'lh-ui family · ink and color',
level: 'M',
tooLong: 'lh-ui'.repeat(600),
}),
methods: {
cycleLevel() {
const order = ['L', 'M', 'Q', 'H']
this.level = order[(order.indexOf(this.level) + 1) % order.length]
},
},
}
</script>
# Error correction level and version
level has the four steps L / M / Q / H (M by default); the higher the level, the more redundancy and the fewer bytes fit. version is 1-40 (0 by default = automatically pick the smallest version that fits). When version is fixed and the text exceeds that version's capacity, encoding throws; the component guards with try/catch, falls back to the empty state, and console.warns:
<LhQrcode value="https://lhgb.top" level="H" :version="10" />
# Size and quiet zone
size controls the rendered SVG width / height (written to the root CSS variable --lh-qrcode-size, 120 by default); margin is the quiet-zone module count (4 by default, the spec minimum), already included in the viewBox:
<LhQrcode value="Ink and color" :size="160" :margin="2" />
# Colors
color is the module color and bgColor the background color (rendered as a <rect> covering the whole viewBox); when color is not passed, the --lh-text-primary token is the fallback, and when bgColor is not passed the background is transparent (the root container's background shows through):
<LhQrcode value="Cinnabar" color="#A63D40" bg-color="#F6F1EA" />
# Props
| Prop | Description | Type | Default |
|---|---|---|---|
| value | Text to encode (UTF-8, Chinese supported) | string | '' |
| level | Error correction level | 'L' \| 'M' \| 'Q' \| 'H' | 'M' |
| version | Version 1-40 (0 = auto-pick the smallest version that fits) | number | 0 |
| margin | Quiet-zone module count | number | 4 |
| color | Foreground color (module color; falls back to the lh-qrcode token when not passed) | string | — |
| bgColor | Background color (falls back to the lh-qrcode token when not passed) | string | — |
| size | Size in px (rendered canvas size) | number | 120 |
| label | Accessibility name (falls back to the default "QR code" message) | string | — |
# Accessibility
The root element has role="img" + aria-label (label can override the default "QR code"). When value is empty or an over-capacity fallback happens, no svg is emitted and the root node keeps the lh-qrcode--empty modifier.
Copyright © 2024-2026 FengMo WenXue