Appearance
Class: UtilsQRCode
QR code utilities for generating images directly in an app or widget.
Remarks
Available everywhere via k.Utils.QRCode. All methods are static.
Example
ts
const src = await k.Utils.QRCode.toDataURL('https://kappapps.app', {
width: 320,
margin: 2,
});
document.querySelector<HTMLImageElement>('#qr')!.src = src;Constructors
Constructor
ts
new UtilsQRCode(): UtilsQRCode;Returns
UtilsQRCode
Methods
toDataURL()
ts
static toDataURL(content, options?): Promise<string>;Generates a QR code as a PNG data URL, ready to use as an image source.
Parameters
content
string
Text or URL to encode. It must not be empty.
options?
QRCodeOptions = {}
Optional dimensions, margin, colors, and error-correction level.
Returns
Promise<string>
A data:image/png;base64,... URL.
Throws
TypeError when content is empty.
Example
ts
const image = document.createElement('img');
image.alt = 'Open the viewers page';
image.src = await k.Utils.QRCode.toDataURL(viewersUrl, {
width: 256,
errorCorrectionLevel: 'H',
color: { dark: '#7c3aedff', light: '#ffffffff' },
});
document.body.appendChild(image);