React library

Library API reference

Every entry point, component, function, constant and type the qrdx package exports, with types and defaults. For HTTP endpoints, see the REST API.

This page lists what qrdx exports, by entry point and by task, with each prop's type and default. The feature pages explain how to use them; this one is for looking a name up.

Entry points

Import fromWhat it hasNeeds
qrdxThe React components (QRCode, QRCodeSVG, QRCodeCanvas, getQRAsSVG) plus everything in qrdx/corereact, react-dom
qrdx/coreThe whole engine without React: markup, downloads, print files, the scan score, frames, templates, art and typesNothing
qrdx/vanillacreateQRCode, plus qrdx/coreA DOM
qrdx/elementThe <qrdx-code> custom element: QRdxCodeElement, defineQRdxCode, toQRdxCodeHTMLA DOM to draw; nothing to render markup
qrdx/element/defineRegisters <qrdx-code> on importA DOM
qrdx/nodegetQRAsPNG@resvg/resvg-js or sharp
qrdx/vueQRCode, QRCodeSVG, useQRCode, plus qrdx/corevue 3.3 or newer
qrdx/preactQRCode, QRCodeSVGpreact 10 or newer
qrdx/solidQRCode, QRCodeSVGsolid-js 1.8 or newer
qrdx/angularThe QRCode component (<qrdx-qr-code>), plus qrdx/core@angular/core 20 or newer
qrdx/typesEvery type, option list and zod schema, without the rendererNothing

Every framework package is an optional peer dependency: installing qrdx never adds one you do not use. jspdf is optional too, for PDF.

Components

QRCode

The component for most uses. QRProps plus a simple logo API, rendered as an <svg>. It uses no browser-only hooks, so it renders in React Server Components.

components/example.tsx
import { QRCode } from "qrdx";

<QRCode value="https://example.com" size={256} margin={4} level="H" logo="/logo.png" />;
PropTypeDefaultWhat it does
valuestringrequiredThe text or URL to encode, exactly as given
sizenumber128Width and height in pixels. A frame adds to it; a template fits inside it
scalenumber1Multiplies size
level"L" | "M" | "Q" | "H""Q"Error correction: about 7%, 15%, 25% or 30% of the code may be damaged
marginnumber0Quiet zone around the code, in modules. The standard asks for 4
fgColorColorConfig"#000000"Color of the data modules: a CSS color, a gradient or an image fill
bgColorColorConfig"#FFFFFF"Background. "transparent" paints none
eyeColorColorConfigfgColorColor of the three corner eyes
dotColorColorConfigfgColorColor of the dot inside each eye
eyeColorsEyeColorsnonePer-eye outer and inner colors for topLeft, topRight and bottomLeft; each overrides eyeColor and dotColor
bodyPatternBodyPattern"circle"Shape of the data modules, one of 23
cornerEyePatternCornerEyePattern"gear"Shape of the corner eyes, one of 17
cornerEyeDotPatternCornerEyeDotPattern"circle"Shape of the eye dots, one of 21
moduleScalenumber1Size of each data module, 0.5 to 1. Each pattern stops at the smallest size that still scans (MODULE_SCALE_FLOOR)
logostringnoneA path, URL or data URL drawn in the middle, with the modules behind it cleared. No logo is drawn without it
logoOptionsLogoOptionsnoneThe logo's size (0.1 to 0.3, default 0.25), padding (0 to 2 modules), x and y (0 to 1), shape and plate
hideLogobooleanfalseHides the logo even when logo is set
autoLevelbooleanfalseRaises level to H when the logo covers more than 7% of the code (AUTO_LEVEL_LOGO_COVERAGE)
frameAnyQRFramenoneA call-to-action frame: { style, text, color, textColor, secondaryText, secondaryColor, fontScale }, or { style: "custom", spec }. The output grows to fit it
templateIdstringnoneA template drawn at size with the code inside: "Arrow", "StandardBox", "SquareBorder", "StrikedBox", "Halloween", "DotRing" or "default"
customTemplateTemplateDefinitionnoneA template you draw in code. Wins over templateId
customPropsRecord<string, any>noneProps for the template's wrapper, such as DotRingProps
shape"square" | "circle" | "heart" | QRSilhouette"square"Puts the code in a disc, a heart or your own outline filled with decorative modules
artQRArtnoneBlends a picture into the modules: { mode, image, intensity, variant, matchEyes }
styleCSSPropertiesnoneInline styles for the <svg>
frameLabelMarkersbooleanfalseFor editors: marks each frame label <text> with data-qrdx-frame-label. Exports never include it
partMarkersbooleanfalseFor editors: marks the drawn parts with data-qrdx-part. Exports never include it
isOGContextbooleanfalseDraws the logo as a positioned <img> for Open Graph image renderers

QRCode takes these props only; any other prop is dropped. QRCodeSVG puts any other prop (className, aria-label, role, data-*, …) on the <svg>, or on the frame's outer <svg> when there is a frame. Event handlers are left out of the markup.

QRCodeSVG

QRProps plus React's SVG attributes (QRPropsSVG): the same props as QRCode without logo, logoOptions, hideLogo and scale. The logo is imageSettings, in pixels:

FieldTypeDefaultWhat it does
srcstringrequiredThe image, as a URL or data URL
width, heightnumberrequiredSize in the same pixels as size
excavatebooleanrequiredClears the modules behind the image
x, ynumbercenteredTop left corner of the image
paddingnumber0Extra clear space around the image, in pixels, when excavating
shape"square" | "rounded" | "circle""square"Crops the image
platestringnoneA solid plate behind the image, in its shape

A logo bigger than the code can repair is shrunk around its center (capImageSettings, the same budget as QRCode).

QRCodeCanvas

QRProps plus React's canvas attributes (QRPropsCanvas), drawn on a <canvas> at the device's pixel ratio. It draws plain square modules with solid colors: a gradient falls back to its first stop, and the pattern, eye color, eyeColors, moduleScale, art and template props are ignored. It ships with "use client".

getQRAsSVG

getQRAsSVG(props: QRPropsSVG): Promise<JSX.Element> returns the code as a React element with its logo embedded as a data URL. For a string, use toSVGString or getSVGString.

Download and export

FunctionReturnsNotes
downloadQRCode(props, { format, size, filename?, quality? })Promise<void>Saves a file. size is 50 to 5000 px and square; the default file name states the pixel size for raster formats
getQRCodeDataUrl(props, format, size, { quality? })Promise<string>The same file as a data URL
getQRAsWebP(props, { quality? })Promise<Blob>Lossless unless quality is set; encodes itself where the browser cannot
copyQRCodeToClipboard(props, size?)Promise<void>A PNG on the clipboard. Call it from a user gesture
getSVGString(props)Promise<string>SVG markup with the logo embedded
toSVGString(props)stringSVG markup, synchronous, no logo embedding. Runs anywhere
toSVGElement(props, document?)SVGSVGElementThe code as a DOM element
getQRAsSVGDataUri(props)Promise<string>data:image/svg+xml,…, the first step of every export
getQRAsCanvas(props, mimeType, getCanvas?)Promise<string | HTMLCanvasElement>A data URL, or the canvas itself with getCanvas
getQRAsPNG(props, { size?, loadExternalLogos? })Promise<Uint8Array>PNG bytes in Node, from qrdx/node. Needs @resvg/resvg-js or sharp
validateSize(width, height){ isValid, error? }The size rule downloadQRCode applies
getDownloadFilename(format, size, frame?)stringThe default file name
withQRSize(props, size)QRPropsThe props drawn at size, with a pixel logo scaled along
canvasToWebP(canvas, { quality? }), blobToDataUrl(blob), encodeWebPLossless(rgba, width, height)WebP helpers

Constants: DownloadFormat is "png" \| "jpg" \| "webp" \| "svg" \| "pdf" \| "eps"; DOWNLOAD_FORMATS maps each to its MIME type and extension; PRESET_SIZES has small (200), medium (400), large (800), xlarge (1200), 2xl (1600) and 3xl (2000); DEFAULT_SIZE is 128.

FunctionReturnsNotes
getPrintLayout(props, { size, unit?, bleed?, cropMarks?, colorMode? })PrintLayoutPhysical sizes in mm: codeWidth, trimWidth, trimHeight, bleed, pageWidth, pageHeight, moduleSize, moduleCount, maxScanDistance. size is 5 mm to 2 m
getQRAsPrintPDF(props, options)Promise<string>A vector PDF as a data URL. Needs jspdf
getQRAsPrintPDFBuffer(props, options)Promise<ArrayBuffer>The same PDF as bytes, for Node
getQRAsPrintSVG(props, { size, unit? })Promise<string>SVG with width and height in mm or in
downloadPrintPDF(props, options & { filename? }), downloadPrintSVG(props, options & { filename? })Promise<void>Browser downloads of the two
getQRAsEPS(props, { sizeMm?, bleedMm?, colorMode? })Promise<string>EPSF-3.0 text. Throws EPS_IMAGE_FILL_REASON for an image fill
downloadPrintEPS(props, options & { filename? })Promise<void>Browser download
svgToEPS(svg, { width?, colorMode?, bleed?, bleedColor?, title? })Promise<string>Converts any SVG the library renders
epsToDataUrl(eps), hasImageFill(props), rgbToCmyk(color), getQRModuleCount(props)Helpers

PrintOptions: size (number), unit ("mm" or "in", default "mm"), bleed (mm, 0 to 20), cropMarks (boolean), colorMode ("rgb" or "cmyk").

Scan score and detection

FunctionReturnsNotes
getScanScore(props, { sizes?, signal? })Promise<ScanScoreResult>{ score, grade, checks }. Browser only; loads jsQR on demand. Default sizes 96, 160 and 320 px (SCAN_TEST_SIZES)
getImageScanScore(imageOrBlob, options?)Promise<ImageScanScoreResult>The same for an existing image, plus data and version. Browser only
getScanScoreFromPixels(pixels, options?)Promise<ImageScanScoreResult>The image score on RGBA pixels, in Node
scanQRPixels(pixels, expected, { sizes? })Promise<PixelScanResult>Checks that pixels decode to expected, as they are and through the camera model. Node
getScanContrast(props){ ratio, required, inverted }The contrast check on its own
getStylePairRisk(props)StylePairRisk | nullA shape pair some scanners miss, with a fix
handleImageLoad(img, size, returnFullData?)Promise<string | QRCode | "NO_QR">Decodes a QR code from an <img>. See QR detection
downloadImageWithBoundingBox(img, corners, filename)voidSaves the image with the found code outlined

Grades are "great", "ok", "risky" and "fails". Each check is { id, passed, message, fix?, skipped? }. Contrast lines: SCAN_CONTRAST_MIN 4.5, SCAN_CONTRAST_LOW 3, SCAN_CONTRAST_FAIL 1.5, and SCAN_IMAGE_CONTRAST_MIN 7 for a picture in the code and 12 behind it. The weak pairs ship as WEAK_BODY_EYES, WEAK_DOT_EYES, WEAK_SHARP_DOT_EYES, SHARP_DOT_EYE_SAFE_BODIES, WEAK_EYES and WEAK_DOTS.

Logos

FunctionReturnsNotes
getQRData(props)the props with imageSettingsLays logo and logoOptions out for a 1024 px code, capped to the error-correction budget
resolveQRCodeProps(props)QRSVGOptionsQRCode's props as what the renderer draws, scale applied
getLogoSizeLimit({ value, level, margin, shape, autoLevel, logoOptions })numberThe largest logoOptions.size that fits, or 0
getLogoBlockDamage(...), logoFitsBudget(...), getCodewordMap(...), damagedCodewords(...)The budget's parts. LOGO_EC_SAFETY is 0.6
removeLogoBackground(src)Promise<string | null>The logo with its solid background removed, as a PNG data URL. Browser
removeLogoBackdrop(pixels)LogoPixels | nullThe same on RGBA pixels, anywhere

Limits: LOGO_SIZE_MIN 0.1, LOGO_SIZE_MAX 0.3, LOGO_SIZE_DEFAULT 0.25, LOGO_PADDING_MAX 2, LOGO_SHAPES (square, rounded, circle).

Frames

ExportWhat it is
BUILT_IN_FRAMESEvery built-in frame: { style, name, tags, labelOn, spec }, in picker order
BUILT_IN_FRAME_SPECS, getBuiltInFrame(style)The specs by style
frameSpecOf(frame)The spec a frame draws, or null
getFrameColors(frame){ frame, text, accent }, from the options or the spec's defaults
getFrameDimensions(size, frame)The output { width, height } for a code of size px
getFrameLayout(size, frame), getFrameText(frame), getFrameSecondaryText(frame), frameLabels(layout), isFrameActive(frame)Layout helpers
OFFICIAL_FRAMES, OFFICIAL_FRAME_INDEX, getOfficialFrame(id), OFFICIAL_FRAME_COLLECTIONS, OFFICIAL_FRAME_COUNTThe official frame library. The frames are built as a module of their own, so unused they cost nothing
resolveFrameSpec(spec), getFrameSpecIssues(spec), frameSpecSchemaChecks a spec; resolveFrameSpec throws FrameSpecError
importFrameSvg(svg, options)Turns an SVG drawing into a frame spec, with warnings (FRAME_IMPORT_LIMITS)
frameSpecHash(spec)A stable hash of a spec

Constants: FRAME_STYLES (the 19 built-in styles plus none), DEFAULT_FRAME_TEXT ("Scan me"), FRAME_TEXT_MAX_LENGTH (24), FRAME_FONT_SCALE_MIN (0.5), FRAME_FONT_SCALE_MAX (1.5), CUSTOM_FRAME_STYLE ("custom"), GRADIENT_FRAME_DEFAULTS.

Templates

ExportWhat it is
TEMPLATESThe registry: default, Arrow, StandardBox, SquareBorder, StrikedBox, Halloween, DotRing
getTemplate(id)One TemplateDefinition, or undefined
getAllTemplates(), getTemplateIds()The list and the ids
Arrow, StandardBox, SquareBorder, StrikedBox, Halloween, DotRing, defaultTemplateThe definitions themselves. DotRingProps types Dot Ring's customProps

TemplateDefinition<TCustomProps> is { id, name, description?, spec?, wrapper(children, props?, config?) }. The wrapper draws on a 300 by 300 canvas and gets { fgColor, bgColor, ...customProps } and { url, pixelSize }.

Shapes and art

ExportWhat it is
createQRArtImage(pixels, { maxSize?, square? })Samples RGBA pixels into a QRArtImage. Anywhere
loadQRArtImage(source, { mode?, maxSize? })The same from a file, data URL or <img>. Browser
isQRArtActive(art), getQRArtVariant(art), getQRArtColorIssue(props)Art helpers
createQRSilhouette(pixels, { mode?, cells? }), loadQRSilhouette(source, options?)A QRSilhouette for shape, from pixels or a picture
getQRSilhouetteFit(silhouette){ ok: true, share } or { ok: false, reason, message }
isShapedCode(shape), getQRShapePath(...), circleQuietZone(...), getLayoutMargin(...)Shape helpers
clampModuleScale(scale, pattern?), MODULE_SCALE_FLOORThe smallest moduleScale each pattern scans at

Constants: QR_SHAPES (square, circle, heart), QR_CIRCLE_QUIET_MIN (3), QR_SILHOUETTE_MAX_CELLS (64), QR_ART_MODES (logo, halftone), QR_ART_VARIANTS, QR_ART_MAX_SAMPLE_SIZE (192), DEFAULT_ART_INTENSITY (0.6).

Rendering primitives

The React-free renderer, from qrdx/core:

ExportWhat it is
createQRCodeTree(options)The code as plain { type, props, key } nodes (QRNode)
renderToString(tree), renderToDOM(tree, document?)Markup, or DOM nodes
toHyperscript(tree, createElement)The tree as another framework's elements. The Vue and Preact entries are built on it
h(type, props, ...children), Fragment, isQRNode(value)Write a template wrapper without JSX
getQRAsSVGNode(options)Promise<QRNode> with the logo embedded
getQRCodeData(props), getQRCodeSVGProps(props, data)The two halves of resolveQRCodeProps

Utilities

getSolidColor, getContrastRatio, getContrastLevel, getLuminance, hexToRgb, SUPPORTS_PATH2D, getColorString, normalizeColorConfig, isGradient, isImagePaint, decodePNGPixels, sanitizeFrameText and isLatin1Text are described on Utilities.

Types and option lists

The types below come from qrdx, qrdx/core and qrdx/types. The option lists are plain arrays; the zod schemas (qrPropsSchema, frameSchema, frameSpecSchema, colorConfigSchema, qrArtSchema, logoOptionsSchema, imageSettingsSchema and the rest) are built from them.

TypeShape
QRPropsThe props table above, without the logo API
QRCodePropsQRProps plus logo, logoOptions, hideLogo, scale
QRSVGOptionsQRProps plus any root attribute: what the core draws
ColorConfigstring | SolidColor | LinearGradient | RadialGradient | AngularGradient | ImagePaint
LinearGradient{ type: "linear", stops, angle? }; angle in degrees, default 0
RadialGradient{ type: "radial", stops }
AngularGradient{ type: "angular", stops, angle? }
GradientStop{ color, offset }; offset 0 to 100
ImagePaint{ type: "image", src, fit?, scale?, position?, opacity?, underlay? }
ImageSettings, LogoOptions, EyeColorsAs in the tables above
QRFrame{ style: FrameStyle, text?, color?, textColor?, secondaryText?, secondaryColor?, fontScale? }
QRCustomFrame, AnyQRFrame, FrameSpec{ style: "custom", spec, ...labels and colors }, the union, and the spec format
QRArt, QRArtImage{ mode, image, intensity?, variant?, matchEyes? } and { width, height, data }
QRCodeShape, QRSilhouette"square" | "circle" | "heart" or { type: "silhouette", width, height, cells }
TemplateDefinition, BaseTemplateProps, TemplateConfigTemplates
DownloadFormat, DownloadSize, DownloadOptions, PrintOptions, PrintLayout, EPSOptionsExport
ScanScoreResult, ImageScanScoreResult, ScanCheck, ScanGrade, StylePairRiskThe scan score
BodyPattern, CornerEyePattern, CornerEyeDotPattern, FrameStyle, ErrorLevelThe option unions

Option lists: BODY_PATTERN, CORNER_EYE_PATTERNS, CORNER_EYE_DOT_PATTERNS, FRAME_STYLES, QR_SHAPES, LOGO_SHAPES, EYE_POSITIONS. Retired values that still render for saved designs: RETIRED_CORNER_EYE_PATTERNS (curly) and RETIRED_CORNER_EYE_DOT_PATTERNS (diamond, star, banner).

Where things run

  • Anywhere, no DOM: toSVGString, createQRCodeTree, renderToString, getQRData, the frame and template helpers, createQRArtImage, createQRSilhouette, getPrintLayout, getQRAsEPS, getQRAsPrintPDFBuffer, scanQRPixels, toQRdxCodeHTML.
  • Browser: downloadQRCode and the other downloads, copyQRCodeToClipboard, getQRAsCanvas, getScanScore, getImageScanScore, handleImageLoad, loadQRArtImage, loadQRSilhouette, removeLogoBackground, createQRCode, the custom element.
  • Node only: getQRAsPNG from qrdx/node.
  • React Server Components: QRCode, QRCodeSVG and everything that needs no DOM. QRCodeCanvas is a Client Component.

Was this page helpful?

Last updated on

On this page