tav-ui
Version:
37 lines (32 loc) • 999 B
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var lodashEs = require('lodash-es');
var qrcode = require('qrcode');
const renderQrCode = ({
canvas,
content,
width = 0,
options: params = {}
}) => {
const options = lodashEs.cloneDeep(params);
options.errorCorrectionLevel = options.errorCorrectionLevel || getErrorCorrectionLevel(content);
return getOriginWidth(content, options).then((_width) => {
options.scale = width === 0 ? void 0 : width / _width * 4;
return qrcode.toCanvas(canvas, content, options);
});
};
function getOriginWidth(content, options) {
const _canvas = document.createElement("canvas");
return qrcode.toCanvas(_canvas, content, options).then(() => _canvas.width);
}
function getErrorCorrectionLevel(content) {
if (content.length > 36) {
return "M";
} else if (content.length > 16) {
return "Q";
} else {
return "H";
}
}
exports.renderQrCode = renderQrCode;
//# sourceMappingURL=drawCanvas2.js.map