UNPKG

tdesign-mobile-vue

Version:
74 lines (70 loc) 2.85 kB
/** * tdesign v1.10.2 * (c) 2025 TDesign Group * @license MIT */ import { defineComponent, computed, createVNode } from 'vue'; import { QRCodeSubComponentProps } from './props.js'; import { DEFAULT_MINVERSION, DEFAULT_NEED_MARGIN, excavateModules, generatePath } from '../../_common/js/qrcode/utils.js'; import { useQRCode } from '../hooks/useQRCode.js'; import '../../_common/js/qrcode/qrcodegen.js'; import '@babel/runtime/helpers/classCallCheck'; import '@babel/runtime/helpers/createClass'; import '@babel/runtime/helpers/defineProperty'; var QRCodeSVG = defineComponent({ name: "QRCodeSVG", props: QRCodeSubComponentProps, setup: function setup(props) { var _useQRCode = useQRCode({ value: props.value, level: props.level, minVersion: DEFAULT_MINVERSION, includeMargin: DEFAULT_NEED_MARGIN, marginSize: props.marginSize, imageSettings: props.imageSettings, size: props.size }), margin = _useQRCode.margin, cells = _useQRCode.cells, numCells = _useQRCode.numCells, calculatedImageSettings = _useQRCode.calculatedImageSettings; var cellsToDraw = computed(function () { var _calculatedImageSetti; if (props.imageSettings && ((_calculatedImageSetti = calculatedImageSettings.value) === null || _calculatedImageSetti === void 0 ? void 0 : _calculatedImageSetti.excavation) != null) { return excavateModules(cells.value, calculatedImageSettings.value.excavation); } return cells.value; }); var imageNode = computed(function () { if (!props.imageSettings || !calculatedImageSettings.value) return null; return createVNode("image", { "href": props.imageSettings.src, "height": calculatedImageSettings.value.h, "width": calculatedImageSettings.value.w, "x": calculatedImageSettings.value.x + margin.value, "y": calculatedImageSettings.value.y + margin.value, "cross-origin": calculatedImageSettings.value.crossOrigin }, null); }); return function () { var fgPath = generatePath(cellsToDraw.value, margin.value); return createVNode("svg", { "height": props.size, "width": props.size, "viewBox": "0 0 ".concat(numCells.value, " ").concat(numCells.value), "role": "img", "style": props.style }, [!!props.title && createVNode("title", null, [props.title]), createVNode("path", { "fill": props.bgColor, "d": "M0,0 h".concat(numCells.value, "v").concat(numCells.value, "H0z"), "shape-rendering": "crispEdges" }, null), createVNode("path", { "fill": props.fgColor, "d": fgPath, "shape-rendering": "crispEdges" }, null), imageNode.value]); }; } }); export { QRCodeSVG as default }; //# sourceMappingURL=qrcode-svg.js.map